|
| 1 | +"""Integration tests for the /config endpoint.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from fastapi import Request |
| 6 | + |
| 7 | +from configuration import AppConfig, LogicError |
| 8 | +from app.endpoints.config import config_endpoint_handler |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.asyncio |
| 12 | +async def test_config_endpoint_returns_config( |
| 13 | + test_config: AppConfig, |
| 14 | + test_request: Request, |
| 15 | + test_auth: tuple[str, str, bool, str], |
| 16 | +) -> None: |
| 17 | + """Test that config endpoint returns test configuration. |
| 18 | +
|
| 19 | + This integration test verifies: |
| 20 | + - Endpoint handler integrates with configuration system |
| 21 | + - Configuration values are correctly accessed |
| 22 | + - Real noop authentication is used |
| 23 | + - Response structure matches expected format |
| 24 | +
|
| 25 | + Args: |
| 26 | + test_config: Loads test configuration |
| 27 | + test_request: FastAPI request |
| 28 | + test_auth: noop authentication tuple |
| 29 | + """ |
| 30 | + response = await config_endpoint_handler(auth=test_auth, request=test_request) |
| 31 | + |
| 32 | + # Verify that response matches the real configuration |
| 33 | + assert response == test_config.configuration |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.asyncio |
| 37 | +async def test_config_endpoint_returns_current_config( |
| 38 | + current_config: AppConfig, |
| 39 | + test_request: Request, |
| 40 | + test_auth: tuple[str, str, bool, str], |
| 41 | +) -> None: |
| 42 | + """Test that config endpoint returns current configuration (from root). |
| 43 | +
|
| 44 | + This integration test verifies: |
| 45 | + - Endpoint handler integrates with configuration system |
| 46 | + - Configuration values are correctly accessed |
| 47 | + - Real noop authentication is used |
| 48 | + - Response structure matches expected format |
| 49 | +
|
| 50 | + Args: |
| 51 | + current_config: Loads root configuration |
| 52 | + test_request: FastAPI request |
| 53 | + test_auth: noop authentication tuple |
| 54 | + """ |
| 55 | + response = await config_endpoint_handler(auth=test_auth, request=test_request) |
| 56 | + |
| 57 | + # Verify that response matches the root configuration |
| 58 | + assert response == current_config.configuration |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.asyncio |
| 62 | +async def test_config_endpoint_fails_without_configuration( |
| 63 | + test_request: Request, |
| 64 | + test_auth: tuple[str, str, bool, str], |
| 65 | +) -> None: |
| 66 | + """Test that authorization fails when configuration is not loaded. |
| 67 | +
|
| 68 | + This integration test verifies: |
| 69 | + - LogicError is raised when configuration is not loaded |
| 70 | + - Error message indicates configuration is not loaded |
| 71 | +
|
| 72 | + Args: |
| 73 | + test_request: FastAPI request |
| 74 | + test_auth: noop authentication tuple |
| 75 | + """ |
| 76 | + |
| 77 | + # Verify that LogicError is raised when authorization tries to access config |
| 78 | + with pytest.raises(LogicError) as exc_info: |
| 79 | + await config_endpoint_handler(auth=test_auth, request=test_request) |
| 80 | + |
| 81 | + # Verify error message |
| 82 | + assert "configuration is not loaded" in str(exc_info.value) |
0 commit comments