More refactoring

This commit is contained in:
lvrossem
2023-04-18 02:52:26 -06:00
parent d074074b03
commit 3968dfd4eb
10 changed files with 156 additions and 64 deletions

View File

@@ -3,17 +3,17 @@ import random
import pytest
from src.enums import CourseEnum
from tests.base import client, register_user
from tests.base import client, get_headers, register_user
from tests.config.database import clear_db
@pytest.mark.asyncio
async def test_register_creates_progress_of_zero():
async def test_register_should_create_progress_of_zero():
"""Test whether registering a new user initializes all progress values to 0.0"""
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
for course in CourseEnum:
if course != CourseEnum.All:
@@ -27,12 +27,12 @@ async def test_register_creates_progress_of_zero():
@pytest.mark.asyncio
async def test_get_all_returns_all():
async def test_get_all_sould_return_all():
"""Test whether the 'All'-course fetches all course progress values"""
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
response = client.get("/courseprogress/All", headers=headers)
assert response.status_code == 200
@@ -48,7 +48,7 @@ async def test_get_course_progress_without_auth_should_fail():
"""Test whether fetching a course progress value without authentication fails"""
clear_db()
headers = {"Content-Type": "application/json"}
headers = get_headers()
for course in CourseEnum:
response = client.get(f"/courseprogress/{course}", headers=headers)
@@ -64,19 +64,19 @@ async def test_get_nonexisting_course_should_fail():
fake_course = "FakeCourse"
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
response = client.get(f"/courseprogress/{fake_course}", headers=headers)
assert response.status_code == 422
@pytest.mark.asyncio
async def test_patch_course_progress():
async def test_patch_course_progress_should_succeed():
"""Test whether patching the progress value of a course works properly"""
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
for course in CourseEnum:
if course != CourseEnum.All:
@@ -98,7 +98,7 @@ async def test_patch_all_should_patch_all_courses():
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
progress = random.uniform(0, 1)
@@ -128,7 +128,7 @@ async def test_patch_nonexisting_course_should_fail():
fake_course = "FakeCourse"
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
progress = random.uniform(0, 1)
@@ -147,7 +147,7 @@ async def test_patch_course_with_invalid_value_should_fail():
clear_db()
token = await register_user()
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
headers = get_headers(token)
too_high_progress = random.uniform(0, 1) + 2
too_low_progress = random.uniform(0, 1) - 2
@@ -174,7 +174,7 @@ async def test_patch_course_progress_without_auth_should_fail():
"""Test whether updating a course progress value without authentication fails"""
clear_db()
headers = {"Content-Type": "application/json"}
headers = get_headers()
for course in CourseEnum:
response = client.patch(