formatting fixes
Build and Push Docker Image / build-and-push (push) Failing after 23s
Python Code Quality / python-code-quality (push) Failing after 9s
Python Test / python-test (push) Successful in 15s

This commit is contained in:
Brian Bjarke Jensen
2025-11-06 22:06:41 +01:00
parent 41636cce77
commit 0e247a69b0
3 changed files with 14 additions and 26 deletions
+1
View File
@@ -29,6 +29,7 @@ async def lifespan(app_instance: FastAPI) -> AsyncIterator[None]:
yield
# Shutdown: Add cleanup code here if needed
# Instantiate app
app = FastAPI(
docs_url=docs_url,
@@ -58,9 +58,7 @@ def _initialize_token_repository() -> TokenRepositoryInterface:
f"Ensure Redis is running and accessible. Error: {e}"
) from e
except Exception as e:
raise RuntimeError(
f"Failed to initialize Redis token repository: {e}"
) from e
raise RuntimeError(f"Failed to initialize Redis token repository: {e}") from e
def get_token_repository() -> TokenRepositoryInterface:
+12 -23
View File
@@ -25,16 +25,14 @@ def test_api_root_with_auth(app_test_client: TestClient) -> None:
"""Test authenticated API root endpoint returns expected message."""
# First login to get token
login_response = app_test_client.post(
"/api/login",
json={"username": "admin", "password": "password"}
"/api/login", json={"username": "admin", "password": "password"}
)
assert login_response.status_code == 200
token = login_response.json()["access_token"]
# Then access API root with token
response = app_test_client.get(
"/api/",
headers={"Authorization": f"Bearer {token}"}
"/api/", headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
assert response.json() == {"message": "Hello World", "authenticated": True}
@@ -91,14 +89,12 @@ def test_api_root_endpoint_content_type(app_test_client: TestClient) -> None:
"""Test API root endpoint returns JSON content type."""
# Login first to get token
login_response = app_test_client.post(
"/api/login",
json={"username": "admin", "password": "password"}
"/api/login", json={"username": "admin", "password": "password"}
)
token = login_response.json()["access_token"]
response = app_test_client.get(
"/api/",
headers={"Authorization": f"Bearer {token}"}
"/api/", headers={"Authorization": f"Bearer {token}"}
)
assert response.headers["content-type"] == "application/json"
@@ -121,8 +117,7 @@ def test_ready_endpoint_content_type(app_test_client: TestClient) -> None:
def test_login_success(app_test_client: TestClient) -> None:
"""Test successful login returns access token."""
response = app_test_client.post(
"/api/login",
json={"username": "admin", "password": "password"}
"/api/login", json={"username": "admin", "password": "password"}
)
assert response.status_code == 200
data = response.json()
@@ -134,8 +129,7 @@ def test_login_success(app_test_client: TestClient) -> None:
def test_login_invalid_credentials(app_test_client: TestClient) -> None:
"""Test login with invalid credentials returns 401."""
response = app_test_client.post(
"/api/login",
json={"username": "admin", "password": "wrongpassword"}
"/api/login", json={"username": "admin", "password": "wrongpassword"}
)
assert response.status_code == 401
assert response.json() == {"detail": "Invalid username or password"}
@@ -144,10 +138,7 @@ def test_login_invalid_credentials(app_test_client: TestClient) -> None:
@pytest.mark.integration
def test_login_missing_fields(app_test_client: TestClient) -> None:
"""Test login with missing fields returns validation error."""
response = app_test_client.post(
"/api/login",
json={"username": "admin"}
)
response = app_test_client.post("/api/login", json={"username": "admin"})
assert response.status_code == 422
@@ -156,15 +147,13 @@ def test_logout(app_test_client: TestClient) -> None:
"""Test logout endpoint."""
# Login first
login_response = app_test_client.post(
"/api/login",
json={"username": "admin", "password": "password"}
"/api/login", json={"username": "admin", "password": "password"}
)
token = login_response.json()["access_token"]
# Logout
response = app_test_client.post(
"/api/logout",
headers={"Authorization": f"Bearer {token}"}
"/api/logout", headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
assert response.json() == {"message": "Logged out successfully"}