From 982027eb5ab31c2e27fea7a4d6bb53c382603273 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Sat, 16 Apr 2022 22:36:08 +0200 Subject: [PATCH] :white_check_mark: Bumped test-coverage to ~87% --- classquiz/kahoot_importer/get.py | 2 ++ classquiz/routers/quiz.py | 2 +- classquiz/tests/__init__.py | 2 +- classquiz/tests/test_kahoot_get.py | 2 ++ classquiz/tests/test_server.py | 47 ++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/classquiz/kahoot_importer/get.py b/classquiz/kahoot_importer/get.py index 05ad663..5412024 100644 --- a/classquiz/kahoot_importer/get.py +++ b/classquiz/kahoot_importer/get.py @@ -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}") diff --git a/classquiz/routers/quiz.py b/classquiz/routers/quiz.py index cc174fd..60aecc8 100644 --- a/classquiz/routers/quiz.py +++ b/classquiz/routers/quiz.py @@ -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}") diff --git a/classquiz/tests/__init__.py b/classquiz/tests/__init__.py index 767bf09..04cdf13 100644 --- a/classquiz/tests/__init__.py +++ b/classquiz/tests/__init__.py @@ -6,7 +6,7 @@ from classquiz import app class ValueStorage: quiz_id = None - value2 = None + imported_quizzes = [None] example_quiz = { diff --git a/classquiz/tests/test_kahoot_get.py b/classquiz/tests/test_kahoot_get.py index cb345af..9d1f068 100644 --- a/classquiz/tests/test_kahoot_get.py +++ b/classquiz/tests/test_kahoot_get.py @@ -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 diff --git a/classquiz/tests/test_server.py b/classquiz/tests/test_server.py index ed688d1..175a0f6 100644 --- a/classquiz/tests/test_server.py +++ b/classquiz/tests/test_server.py @@ -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"'