Bumped test-coverage to ~87%

This commit is contained in:
Mawoka
2022-04-16 22:36:08 +02:00
parent 24c6b9ca2f
commit 982027eb5a
5 changed files with 53 additions and 2 deletions
+2
View File
@@ -17,5 +17,7 @@ async def get(game_id: str) -> _Response | None:
return _Response(**await response.json())
elif response.status == 404:
return None
elif response.status == 400:
return None
else:
raise Exception(f"Unexpected response status: {response.status}")
+1 -1
View File
@@ -153,7 +153,7 @@ async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)
try:
return await import_quiz(quiz_id, user)
except ValidationError:
raise HTTPException(status_code=400, detail="THis quiz in't (yet) supported")
raise HTTPException(status_code=400, detail="This quiz isn't (yet) supported")
@router.delete("/delete/{quiz_id}")
+1 -1
View File
@@ -6,7 +6,7 @@ from classquiz import app
class ValueStorage:
quiz_id = None
value2 = None
imported_quizzes = [None]
example_quiz = {
+2
View File
@@ -116,3 +116,5 @@ async def test_get():
for i in quiz_list:
rounds = rounds + 1
await get(i)
lol = await get("f183e091-a863-44ec-a1b7-c70eb92e3f6a")
assert lol is None
+47
View File
@@ -313,3 +313,50 @@ class TestQuiz:
resp = test_client.get("/api/v1/quiz/list", cookies={"access_token": token})
assert resp.status_code == 200
assert resp.json()[0]["id"] == ValueStorage.quiz_id
@pytest.mark.asyncio
async def test_update_quiz(self, test_client):
example_quiz["public"] = True
example_quiz["questions"][1]["image"] = "https://i.imgur.com/sSNSy77.png"
resp = test_client.post(
"/api/v1/users/token/cookie", data={"username": test_user_email, "password": test_user_password}
)
token = resp.cookies["access_token"]
resp = test_client.put(f"/api/v1/quiz/update/{ValueStorage.quiz_id}", json=example_quiz,
cookies={"access_token": token})
assert resp.status_code == 200
resp = test_client.put(f"/api/v1/quiz/update/f183e091-a863-44ec-a1b7-c70eb92e3f6a", json=example_quiz,
cookies={"access_token": token})
assert resp.status_code == 404
resp = test_client.put(f"/api/v1/quiz/update/saddsaasddsadsa", json=example_quiz,
cookies={"access_token": token})
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_get_public_quiz(self, test_client):
resp = test_client.post(
"/api/v1/users/token/cookie", data={"username": test_user_email, "password": test_user_password}
)
token = resp.cookies["access_token"]
resp = test_client.get(f"/api/v1/quiz/get/{ValueStorage.quiz_id}", cookies={"access_token": token})
assert resp.status_code == 200
resp = test_client.get(f"/api/v1/quiz/get/public/f183e091-a863-44ec-a1b7-c70eb92e3f6a",
cookies={"access_token": token})
assert resp.status_code == 404
resp = test_client.get(f"/api/v1/quiz/get/public/dadasdas92e3f6a",
cookies={"access_token": token})
assert resp.status_code == 400
@pytest.mark.asyncio
async def test_import_quiz(self, test_client):
resp = test_client.post(
"/api/v1/users/token/cookie", data={"username": test_user_email, "password": test_user_password}
)
token = resp.cookies["access_token"]
resp = test_client.post(f"/api/v1/quiz/import/1f95eb0b-fcf4-4db2-879b-5418ef75116b",
cookies={"access_token": token})
assert resp.status_code == 200
ValueStorage.imported_quizzes.append(resp.json()["id"])
resp = test_client.post(f"/api/v1/quiz/import/1f95eb0bdassdadasdas",
cookies={"access_token": token})
assert resp.text == '"quiz not found"'