mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 15:12:08 +01:00
feat(test): added more tests
This commit is contained in:
@@ -113,25 +113,6 @@ async def test_register_then_login_and_fetch_me(fastapi_app):
|
||||
assert me.status_code == status.HTTP_200_OK
|
||||
assert me.json()["email"] == email
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_revoked_token_blocked_everywhere(fastapi_app, test_user):
|
||||
transport = ASGITransport(app=fastapi_app, raise_app_exceptions=True)
|
||||
async with AsyncClient(transport=transport, base_url="http://testserver") as ac:
|
||||
login = await ac.post("/auth/jwt/login", data=test_user)
|
||||
token = login.json()["access_token"]
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
# Sanity check works before logout
|
||||
ok = await ac.get("/authenticated-route", headers=headers)
|
||||
assert ok.status_code == status.HTTP_200_OK
|
||||
|
||||
# Logout revokes token
|
||||
lo = await ac.post("/auth/jwt/logout", headers=headers)
|
||||
assert lo.status_code in (status.HTTP_200_OK, status.HTTP_204_NO_CONTENT)
|
||||
|
||||
# Token should be rejected on any protected endpoint
|
||||
blocked = await ac.get("/authenticated-route", headers=headers)
|
||||
assert blocked.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_current_user_revokes_access(fastapi_app):
|
||||
|
||||
@@ -63,7 +63,7 @@ async def test_create_transaction_missing_amount_fails(fastapi_app, test_user):
|
||||
resp = await ac.post("/transactions/create", json=invalid_payload, headers=headers)
|
||||
|
||||
# 4. Assert the expected validation error
|
||||
assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
||||
assert resp.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -168,24 +168,3 @@ async def test_delete_transaction_not_found(fastapi_app, test_user):
|
||||
r = await ac.delete("/transactions/999999/delete", headers=h)
|
||||
assert r.status_code == status.HTTP_404_NOT_FOUND
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_debug_csas_endpoints_require_auth_and_queue(fastapi_app, test_user):
|
||||
transport = ASGITransport(app=fastapi_app)
|
||||
async with AsyncClient(transport=transport, base_url="http://testserver") as ac:
|
||||
# unauthenticated should be blocked
|
||||
unauth = await ac.get("/debug/scrape/csas/all")
|
||||
assert unauth.status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN)
|
||||
|
||||
token = (await ac.post("/auth/jwt/login", data=test_user)).json()["access_token"]
|
||||
h = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
all_resp = await ac.get("/debug/scrape/csas/all", headers=h)
|
||||
assert all_resp.status_code == status.HTTP_200_OK
|
||||
assert all_resp.json()["status"] == "queued"
|
||||
|
||||
# Single-user CSAS requires auth and user dep; using current user id via /users/me
|
||||
me = await ac.get("/users/me", headers=h)
|
||||
uid = me.json()["id"]
|
||||
one = await ac.post(f"/debug/scrape/csas/{uid}", headers=h)
|
||||
assert one.status_code == status.HTTP_200_OK
|
||||
assert one.json()["status"] == "queued"
|
||||
|
||||
Reference in New Issue
Block a user