Skip to content

Commit 93de9fe

Browse files
committed
Adding intehration tests of /config endpoint. Moving auth and request fixtures to conftest.py.
1 parent dbb065c commit 93de9fe

File tree

3 files changed

+127
-24
lines changed

3 files changed

+127
-24
lines changed

tests/integration/conftest.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
from pathlib import Path
44

5+
from fastapi import Request
6+
from authentication.noop import NoopAuthDependency
7+
58
from typing import Generator
69
import pytest
710
from sqlalchemy import create_engine
@@ -45,6 +48,25 @@ def test_config_fixture() -> Generator:
4548
# Note: Cleanup is handled by the autouse reset_configuration_state fixture
4649

4750

51+
@pytest.fixture(name="current_config", scope="function")
52+
def current_config_fixture() -> Generator:
53+
"""Load current configuration for integration tests.
54+
55+
This fixture loads the actual configuration file from project root (current configuration),
56+
demonstrating integration with the configuration system.
57+
"""
58+
config_path = (
59+
Path(__file__).parent.parent.parent / "lightspeed-stack.yaml"
60+
)
61+
assert config_path.exists(), f"Config file not found: {config_path}"
62+
63+
# Load configuration
64+
configuration.load_configuration(str(config_path))
65+
66+
yield configuration
67+
# Note: Cleanup is handled by the autouse reset_configuration_state fixture
68+
69+
4870
@pytest.fixture(name="test_db_engine", scope="function")
4971
def test_db_engine_fixture() -> Generator:
5072
"""Create an in-memory SQLite database engine for testing.
@@ -81,3 +103,26 @@ def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None,
81103
yield session
82104

83105
session.close()
106+
107+
108+
@pytest.fixture(name="test_request")
109+
def test_request_fixture() -> Request:
110+
"""Create a test FastAPI Request object with proper scope."""
111+
return Request(
112+
scope={
113+
"type": "http",
114+
"query_string": b"",
115+
"headers": [],
116+
}
117+
)
118+
119+
120+
@pytest.fixture(name="test_auth")
121+
async def test_auth_fixture(test_request: Request) -> tuple[str, str, bool, str]:
122+
"""Create authentication using real noop auth module.
123+
124+
This uses the actual NoopAuthDependency instead of mocking,
125+
making this a true integration test.
126+
"""
127+
noop_auth = NoopAuthDependency()
128+
return await noop_auth(test_request)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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)

tests/integration/endpoints/test_info_integration.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from configuration import AppConfig
1212
from app.endpoints.info import info_endpoint_handler
13-
from authentication.noop import NoopAuthDependency
1413
from version import __version__
1514

1615

@@ -36,29 +35,6 @@ def mock_llama_stack_client_fixture(
3635
yield mock_client
3736

3837

39-
@pytest.fixture(name="test_request")
40-
def test_request_fixture() -> Request:
41-
"""Create a test FastAPI Request object with proper scope."""
42-
return Request(
43-
scope={
44-
"type": "http",
45-
"query_string": b"",
46-
"headers": [],
47-
}
48-
)
49-
50-
51-
@pytest.fixture(name="test_auth")
52-
async def test_auth_fixture(test_request: Request) -> tuple[str, str, bool, str]:
53-
"""Create authentication using real noop auth module.
54-
55-
This uses the actual NoopAuthDependency instead of mocking,
56-
making this a true integration test.
57-
"""
58-
noop_auth = NoopAuthDependency()
59-
return await noop_auth(test_request)
60-
61-
6238
@pytest.mark.asyncio
6339
async def test_info_endpoint_returns_service_information(
6440
test_config: AppConfig,

0 commit comments

Comments
 (0)