diff --git a/test/conftest.py b/test/conftest.py index 58b5dc5..416dcc6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -45,6 +45,19 @@ async def default_client(db_session) -> AsyncGenerator[AsyncClient, None]: app.dependency_overrides.clear() +@pytest.fixture +async def no_user_client(db_session) -> AsyncGenerator[AsyncClient, None]: + def get_db_override(): + return db_session + app.dependency_overrides[get_db] = get_db_override + transport = ASGITransport(app=app) + async with AsyncClient(transport=transport, base_url="http://localhost:8000/api/v1") as ac: + yield ac + + app.dependency_overrides.clear() + + + @pytest.fixture async def no_su_client(db_session) -> AsyncGenerator[AsyncClient, None]: def get_db_override(): diff --git a/test/test_auth_user.py b/test/test_auth_user.py new file mode 100644 index 0000000..e5ce189 --- /dev/null +++ b/test/test_auth_user.py @@ -0,0 +1,23 @@ +""" +This testing module removes the testing user override to verify that endpoints with only the user requirement return a 401 error when not logged in +""" +import pytest +from httpx import AsyncClient + +from .conftest import no_user_client + + +@pytest.mark.anyio +async def test_get_self_db(no_user_client: AsyncClient): + resp = await no_user_client.get("/user/self/db") + assert resp.status_code != 422 + assert resp.status_code == 401 + assert resp.json()["detail"] == "Not authenticated" + + +@pytest.mark.anyio +async def test_post_org_success(no_user_client: AsyncClient): + resp = await no_user_client.post("/org", json={"name": "New Test Org"}) + assert resp.status_code != 422 + assert resp.status_code == 401 + assert resp.json()["detail"] == "Not authenticated"