Skip to content

Commit

Permalink
cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
JibrilExe committed Mar 24, 2024
1 parent d503d67 commit 7eabc7a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion backend/project/utils/query_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def create_model_instance(model: DeclarativeMeta,
return {"error": f"Missing required fields: {', '.join(missing_fields)}",
"url": response_url_base}, 400


filtered_data = filter_model_fields(model, data)
new_instance: DeclarativeMeta = model(**filtered_data)
db.session.add(new_instance)
Expand Down
2 changes: 1 addition & 1 deletion backend/test_auth_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def get(self):
app = Flask(__name__)
app.register_blueprint(index_bp)

app.run(debug=True, host='0.0.0.0')
app.run(debug=True, host='0.0.0.0', port=5001)
2 changes: 2 additions & 0 deletions backend/tests/endpoints/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def course_empty_name():
def invalid_course():
"""An invalid course for testing."""
return {"invalid": "error"}

@pytest.fixture
def valid_course_entry(session, valid_course):
"""A valid course for testing that's already in the db"""
course = Course(**valid_course)
Expand Down
30 changes: 17 additions & 13 deletions backend/tests/endpoints/course/courses_test.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
"""Here we will test all the courses endpoint related functionality"""


class TestCourseEndpoint:
"""Class for testing the courses endpoint"""

def test_post_courses(self, client, valid_course,invalid_course):
def test_post_courses(self, client, valid_course, invalid_course):
"""
Test posting a course to the /courses endpoint
"""

response = client.post("/courses", json=valid_course, headers={"Authorization":"teacher2"})
response = client.post("/courses", json=valid_course,
headers={"Authorization": "teacher2"})
assert response.status_code == 201
data = response.json
assert data["data"]["name"] == "Sel"
assert data["data"]["teacher"] == valid_course["teacher"]

# Is reachable using the API
get_response = client.get(f"/courses/{data['data']['course_id']}",
headers={"Authorization":"teacher2"})
headers={"Authorization": "teacher2"})
assert get_response.status_code == 200

response = client.post(
"/courses?uid=Bart", json=invalid_course
"/courses?uid=Bart", json=invalid_course,
headers={"Authorization": "teacher2"}
) # invalid course
assert response.status_code == 400

def test_post_no_name(self, client, course_empty_name):
"""
Test posting a course with a blank name
"""

response = client.post("/courses?uid=Bart", json=course_empty_name)
assert response.status_code == 400
response = client.post("/courses?uid=Bart", json=course_empty_name,
headers={"Authorization": "teacher2"})
assert response.status_code == 400

def test_post_courses_course_id_students_and_admins(
self, client, valid_course_entry, valid_students_entries):
Expand All @@ -45,18 +49,18 @@ def test_post_courses_course_id_students_and_admins(

response = client.post(
sel2_students_link + f"/students?uid={valid_course_entry.teacher}",
json={"students": valid_students}, headers={"Authorization":"teacher2"}
json={"students": valid_students}, headers={"Authorization": "teacher2"}
)

assert response.status_code == 403


def test_get_courses(self, valid_course_entries, client):
"""
Test all the getters for the courses endpoint
"""

response = client.get("/courses", headers={"Authorization":"teacher1"})
response = client.get(
"/courses", headers={"Authorization": "teacher1"})
assert response.status_code == 200
data = response.json
for course in valid_course_entries:
Expand All @@ -66,13 +70,13 @@ def test_course_delete(self, valid_course_entry, client):
"""Test all course endpoint related delete functionality"""

response = client.delete(
"/courses/" + str(valid_course_entry.course_id), headers={"Authorization":"teacher2"}
"/courses/" + str(valid_course_entry.course_id), headers={"Authorization": "teacher2"}
)
assert response.status_code == 200

# Is not reachable using the API
get_response = client.get(f"/courses/{valid_course_entry.course_id}",
headers={"Authorization":"teacher2"})
headers={"Authorization": "teacher2"})
assert get_response.status_code == 404

def test_course_patch(self, valid_course_entry, client):
Expand All @@ -81,7 +85,7 @@ def test_course_patch(self, valid_course_entry, client):
"""
response = client.patch(f"/courses/{valid_course_entry.course_id}", json={
"name": "TestTest"
}, headers={"Authorization":"teacher2"})
}, headers={"Authorization": "teacher2"})
data = response.json
assert response.status_code == 200
assert data["data"]["name"] == "TestTest"

0 comments on commit 7eabc7a

Please sign in to comment.