Finish off backend tests

This commit is contained in:
lvrossem
2023-04-10 16:07:25 -06:00
parent 8e128ca033
commit 73ce1bf2e0
9 changed files with 285 additions and 72 deletions

View File

@@ -1,23 +1,13 @@
import random
import sys
import pytest
from fastapi.testclient import TestClient
sys.path.append("..")
from src.enums import CourseEnum
from src.main import app, get_db
from tests.base import avatar, client, password, username
from tests.config.database import clear_db, override_get_db
app.dependency_overrides[get_db] = override_get_db
client = TestClient(app)
username = "user1"
password = "password"
avatar = "lion"
async def register_user():
response = client.post(
@@ -67,6 +57,19 @@ async def test_get_all_returns_all():
assert {"progress_value": 0.0, "course": course} in response
@pytest.mark.asyncio
async def test_get_course_progress_value_without_auth_should_fail():
"""Test whether fetching a course progress value without authentication fails"""
clear_db()
headers = {"Content-Type": "application/json"}
for course in CourseEnum:
response = client.get(f"/courseprogress/{course}", headers=headers)
assert response.status_code == 403
@pytest.mark.asyncio
async def test_get_nonexisting_course_should_fail():
"""Test whether fetching the progress of a nonexisting course fails"""
@@ -178,3 +181,20 @@ async def test_patch_course_with_invalid_value_should_fail():
)
assert response.status_code == 400
@pytest.mark.asyncio
async def test_patch_course_progress_value_without_auth_should_fail():
"""Test whether updating a course progress value without authentication fails"""
clear_db()
headers = {"Content-Type": "application/json"}
for course in CourseEnum:
response = client.patch(
f"/courseprogress/{course}",
headers=headers,
json={"progress_value": random.uniform(0, 1)},
)
assert response.status_code == 403