✅ Bumped test-coverage to ~87%
This commit is contained in:
@@ -17,5 +17,7 @@ async def get(game_id: str) -> _Response | None:
|
|||||||
return _Response(**await response.json())
|
return _Response(**await response.json())
|
||||||
elif response.status == 404:
|
elif response.status == 404:
|
||||||
return None
|
return None
|
||||||
|
elif response.status == 400:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unexpected response status: {response.status}")
|
raise Exception(f"Unexpected response status: {response.status}")
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)
|
|||||||
try:
|
try:
|
||||||
return await import_quiz(quiz_id, user)
|
return await import_quiz(quiz_id, user)
|
||||||
except ValidationError:
|
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}")
|
@router.delete("/delete/{quiz_id}")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from classquiz import app
|
|||||||
|
|
||||||
class ValueStorage:
|
class ValueStorage:
|
||||||
quiz_id = None
|
quiz_id = None
|
||||||
value2 = None
|
imported_quizzes = [None]
|
||||||
|
|
||||||
|
|
||||||
example_quiz = {
|
example_quiz = {
|
||||||
|
|||||||
@@ -116,3 +116,5 @@ async def test_get():
|
|||||||
for i in quiz_list:
|
for i in quiz_list:
|
||||||
rounds = rounds + 1
|
rounds = rounds + 1
|
||||||
await get(i)
|
await get(i)
|
||||||
|
lol = await get("f183e091-a863-44ec-a1b7-c70eb92e3f6a")
|
||||||
|
assert lol is None
|
||||||
|
|||||||
@@ -313,3 +313,50 @@ class TestQuiz:
|
|||||||
resp = test_client.get("/api/v1/quiz/list", cookies={"access_token": token})
|
resp = test_client.get("/api/v1/quiz/list", cookies={"access_token": token})
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert resp.json()[0]["id"] == ValueStorage.quiz_id
|
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"'
|
||||||
|
|||||||
Reference in New Issue
Block a user