The great endpoint refactor

This commit is contained in:
lvrossem
2023-04-10 14:44:21 -06:00
parent e7145369b5
commit 8e128ca033
8 changed files with 100 additions and 40 deletions

View File

@@ -52,6 +52,7 @@ async def test_register_creates_progress_of_zero():
@pytest.mark.asyncio
async def test_get_all_returns_all():
"""Test whether the 'All'-course fetches all course progress values"""
clear_db()
token = await register_user()
@@ -68,6 +69,7 @@ async def test_get_all_returns_all():
@pytest.mark.asyncio
async def test_get_nonexisting_course_should_fail():
"""Test whether fetching the progress of a nonexisting course fails"""
clear_db()
token = await register_user()
@@ -81,6 +83,7 @@ async def test_get_nonexisting_course_should_fail():
@pytest.mark.asyncio
async def test_patch_course_progress():
"""Test whether patching the progress value of a course works properly"""
clear_db()
token = await register_user()
@@ -91,9 +94,9 @@ async def test_patch_course_progress():
progress_value = random.uniform(0, 1)
response = client.patch(
f"/courseprogress",
f"/courseprogress/{course}",
headers=headers,
json={"progress_value": progress_value, "course": course},
json={"progress_value": progress_value},
)
assert response.status_code == 200
@@ -102,6 +105,7 @@ async def test_patch_course_progress():
@pytest.mark.asyncio
async def test_patch_all_should_patch_all_courses():
"""Test whether patching the 'All'-course updates all progress values"""
clear_db()
token = await register_user()
@@ -110,9 +114,9 @@ async def test_patch_all_should_patch_all_courses():
progress_value = random.uniform(0, 1)
response = client.patch(
f"/courseprogress",
"/courseprogress/All",
headers=headers,
json={"progress_value": progress_value, "course": "All"},
json={"progress_value": progress_value},
)
assert response.status_code == 200
@@ -129,6 +133,7 @@ async def test_patch_all_should_patch_all_courses():
@pytest.mark.asyncio
async def test_patch_nonexisting_course_should_fail():
"""Test whether patching a nonexisting course fails"""
clear_db()
token = await register_user()
@@ -139,9 +144,9 @@ async def test_patch_nonexisting_course_should_fail():
progress_value = random.uniform(0, 1)
response = client.patch(
f"/courseprogress",
f"/courseprogress/{fake_course}",
headers=headers,
json={"progress_value": progress_value, "course": fake_course},
json={"progress_value": progress_value},
)
assert response.status_code == 422
@@ -149,6 +154,7 @@ async def test_patch_nonexisting_course_should_fail():
@pytest.mark.asyncio
async def test_patch_course_with_invalid_value_should_fail():
"""Test whether patching a course progress value with an invalid value fails"""
clear_db()
token = await register_user()
@@ -158,17 +164,17 @@ async def test_patch_course_with_invalid_value_should_fail():
too_low_progress_value = random.uniform(0, 1) - 2
response = client.patch(
f"/courseprogress",
"/courseprogress/All",
headers=headers,
json={"progress_value": too_high_progress_value, "course": "All"},
json={"progress_value": too_high_progress_value},
)
assert response.status_code == 400
response = client.patch(
f"/courseprogress",
"/courseprogress/All",
headers=headers,
json={"progress_value": too_low_progress_value, "course": "All"},
json={"progress_value": too_low_progress_value},
)
assert response.status_code == 400