Skip to content

Commit 36d0a94

Browse files
authored
Merge pull request #733 from xmican10/LCORE_713_config_endpoint
Adding integration tests of /config endpoint. Moving auth and request fictures to conftest.py.
2 parents 6361e59 + 1c8f252 commit 36d0a94

File tree

3 files changed

+134
-28
lines changed

3 files changed

+134
-28
lines changed

tests/integration/conftest.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
"""Shared fixtures for integration tests."""
22

33
from pathlib import Path
4-
54
from typing import Generator
5+
66
import pytest
7+
from fastapi import Request
8+
79
from sqlalchemy import create_engine
810
from sqlalchemy.orm import sessionmaker, Session
911
from sqlalchemy.engine import Engine
1012

13+
from authentication.noop import NoopAuthDependency
14+
from authentication.interface import AuthTuple
15+
1116
from configuration import configuration
1217
from models.database.base import Base
1318

@@ -45,6 +50,23 @@ def test_config_fixture() -> Generator:
4550
# Note: Cleanup is handled by the autouse reset_configuration_state fixture
4651

4752

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

tests/integration/endpoints/test_info_integration.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from fastapi import HTTPException, Request, status
88
from llama_stack_client import APIConnectionError
99
from llama_stack_client.types import VersionInfo
10+
from authentication.interface import AuthTuple
1011

1112
from configuration import AppConfig
1213
from app.endpoints.info import info_endpoint_handler
13-
from authentication.noop import NoopAuthDependency
1414
from version import __version__
1515

1616

@@ -36,35 +36,12 @@ def mock_llama_stack_client_fixture(
3636
yield mock_client
3737

3838

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-
6239
@pytest.mark.asyncio
6340
async def test_info_endpoint_returns_service_information(
6441
test_config: AppConfig,
6542
mock_llama_stack_client: AsyncMockType,
6643
test_request: Request,
67-
test_auth: tuple[str, str, bool, str],
44+
test_auth: AuthTuple,
6845
) -> None:
6946
"""Test that info endpoint returns correct service information.
7047
@@ -100,7 +77,7 @@ async def test_info_endpoint_handles_connection_error(
10077
test_config: AppConfig,
10178
mock_llama_stack_client: AsyncMockType,
10279
test_request: Request,
103-
test_auth: tuple[str, str, bool, str],
80+
test_auth: AuthTuple,
10481
mocker: MockerFixture,
10582
) -> None:
10683
"""Test that info endpoint properly handles Llama Stack connection errors.
@@ -140,7 +117,7 @@ async def test_info_endpoint_uses_configuration_values(
140117
test_config: AppConfig,
141118
mock_llama_stack_client: AsyncMockType,
142119
test_request: Request,
143-
test_auth: tuple[str, str, bool, str],
120+
test_auth: AuthTuple,
144121
) -> None:
145122
"""Test that info endpoint correctly uses configuration values.
146123

0 commit comments

Comments
 (0)