From 548e1265a4c155b0583a1c0023e58cc177803a76 Mon Sep 17 00:00:00 2001 From: Siebe Vlietinck Date: Wed, 20 Mar 2024 13:17:48 +0100 Subject: [PATCH] made requested changes --- backend/project/endpoints/users.py | 7 ++++--- backend/tests/endpoints/conftest.py | 2 +- backend/tests/endpoints/project_test.py | 5 +---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/backend/project/endpoints/users.py b/backend/project/endpoints/users.py index 3a945467..53f00805 100644 --- a/backend/project/endpoints/users.py +++ b/backend/project/endpoints/users.py @@ -56,6 +56,7 @@ def post(self): uid = request.json.get('uid') is_teacher = request.json.get('is_teacher') is_admin = request.json.get('is_admin') + url = f"{API_URL}/users" if is_teacher is None or is_admin is None or uid is None: return { @@ -64,7 +65,7 @@ def post(self): "uid": "User ID (string)", "is_teacher": "Teacher status (boolean)", "is_admin": "Admin status (boolean)" - },"url": f"{API_URL}/users" + },"url": url }, 400 try: user = db.session.get(userModel, uid) @@ -76,13 +77,13 @@ def post(self): db.session.add(new_user) db.session.commit() return jsonify({"message": "User created successfully!", - "data": user, "url": f"{API_URL}/users/{user.uid}", "status_code": 201}) + "data": user, "url": f"{url}/{user.uid}", "status_code": 201}) except SQLAlchemyError: # every exception should result in a rollback db.session.rollback() return {"message": "An error occurred while creating the user", - "url": f"{API_URL}/users"}, 500 + "url": url}, 500 class User(Resource): diff --git a/backend/tests/endpoints/conftest.py b/backend/tests/endpoints/conftest.py index 2ec75f92..d3a32c9a 100644 --- a/backend/tests/endpoints/conftest.py +++ b/backend/tests/endpoints/conftest.py @@ -200,8 +200,8 @@ def client(app): def valid_teacher_entry(session): """A valid teacher for testing that's already in the db""" teacher = User(uid="Bart", is_teacher=True, is_admin=False) - session.add(teacher) try: + session.add(teacher) session.commit() except SQLAlchemyError: session.rollback() diff --git a/backend/tests/endpoints/project_test.py b/backend/tests/endpoints/project_test.py index 13e265fa..2cda69b6 100644 --- a/backend/tests/endpoints/project_test.py +++ b/backend/tests/endpoints/project_test.py @@ -77,10 +77,7 @@ def test_remove_project(client, valid_project_entry): assert response.status_code == 404 def test_patch_project(client, valid_project_entry): - """ - Test functionality of the PATCH method for projects - Test functionality of the PATCH method for projects - """ + """Test functionality of the PATCH method for projects""" project_id = valid_project_entry.project_id