Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_config_fixture() -> Generator:

This fixture loads the actual configuration file used in testing,
demonstrating integration with the configuration system.

Yields:
The `configuration` module with the loaded settings.
"""
config_path = (
Path(__file__).parent.parent / "configuration" / "lightspeed-stack.yaml"
Expand All @@ -56,6 +59,9 @@ def current_config_fixture() -> Generator:

This fixture loads the actual configuration file from project root (current configuration),
demonstrating integration with the configuration system.

Yields:
configuration: The loaded configuration object.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"""
config_path = Path(__file__).parent.parent.parent / "lightspeed-stack.yaml"
assert config_path.exists(), f"Config file not found: {config_path}"
Expand All @@ -73,6 +79,9 @@ def test_db_engine_fixture() -> Generator:

This provides a real database (not mocked) for integration tests.
Each test gets a fresh database.

Yields:
engine (Engine): A SQLAlchemy Engine connected to a new in-memory SQLite database.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"""
# Create in-memory SQLite database
engine = create_engine(
Expand All @@ -96,6 +105,10 @@ def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None,
"""Create a database session for testing.

Provides a real database session connected to the in-memory test database.

Yields:
session (Session): A database session bound to the test engine; the
fixture closes the session after the test.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
"""
session_local = sessionmaker(autocommit=False, autoflush=False, bind=test_db_engine)
session = session_local()
Expand All @@ -107,7 +120,12 @@ def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None,

@pytest.fixture(name="test_request")
def test_request_fixture() -> Request:
"""Create a test FastAPI Request object with proper scope."""
"""Create a test FastAPI Request object with proper scope.

Returns:
request (fastapi.Request): A Request object whose scope has `"type":
"http"`, an empty `query_string`, and no headers.
"""
return Request(
scope={
"type": "http",
Expand All @@ -119,7 +137,11 @@ def test_request_fixture() -> Request:

@pytest.fixture(name="test_response")
def test_response_fixture() -> Response:
"""Create a test FastAPI Response object with proper scope."""
"""Create a test FastAPI Response object with proper scope.

Returns:
Response: Response with empty content, status 200, and media_type "application/json".
"""
return Response(content="", status_code=200, media_type="application/json")


Expand All @@ -129,6 +151,9 @@ async def test_auth_fixture(test_request: Request) -> AuthTuple:

This uses the actual NoopAuthDependency instead of mocking,
making this a true integration test.

Returns:
AuthTuple: Authentication information produced by NoopAuthDependency.
"""
noop_auth = NoopAuthDependency()
return await noop_auth(test_request)
14 changes: 13 additions & 1 deletion tests/integration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ def test_default_configuration() -> None:


def test_loading_proper_configuration(configuration_filename: str) -> None:
"""Test the configuration loading."""
"""Test the configuration loading.

Validate that loading the given configuration YAML populates all expected sections and values.

Loads configuration from the provided file and asserts presence and
correctness of top-level sections (configuration, service, llama_stack,
user_data_collection, mcp_servers) and selected field values including
service host and flags, CORS settings, llama stack URL and API key secret,
user data collection settings, and three MCP server entries.

Parameters:
configuration_filename (str): Path to the YAML configuration file used for the test.
"""
cfg = configuration
cfg.load_configuration(configuration_filename)

Expand Down
39 changes: 35 additions & 4 deletions tests/integration/test_rh_identity_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

@pytest.fixture
def client() -> Generator[TestClient, None, None]:
"""Create test client for FastAPI app with RH Identity config."""
"""Create test client for FastAPI app with RH Identity config.

Provides a TestClient for the FastAPI application configured with the RH
Identity test configuration.

Returns:
TestClient: A test client instance for the FastAPI app.
"""
Comment thread
coderabbitai[bot] marked this conversation as resolved.
# Save original env var if it exists
original_config = os.environ.get("LIGHTSPEED_STACK_CONFIG_PATH")

Expand Down Expand Up @@ -63,7 +70,16 @@ def user_identity_json() -> dict:

@pytest.fixture
def system_identity_json() -> dict:
"""Fixture providing valid System identity JSON."""
"""Fixture providing valid System identity JSON.

Provide a valid RH Identity "System" payload suitable for tests.

Returns:
dict: JSON with keys:
- "identity": contains "account_number", "org_id", "type" set to
"System", and "system" with "cn".
- "entitlements": contains "rhel" with "is_entitled" and "is_trial" boolean flags.
"""
return {
"identity": {
"account_number": "456",
Expand All @@ -78,7 +94,14 @@ def system_identity_json() -> dict:


def encode_identity(identity_json: dict) -> str:
"""Encode identity JSON to base64."""
"""Encode identity JSON to base64.

Parameters:
identity_json (dict): JSON-serializable identity payload to encode.

Returns:
str: Base64-encoded UTF-8 string representation of the JSON payload.
"""
json_str = json.dumps(identity_json)
return base64.b64encode(json_str.encode("utf-8")).decode("utf-8")

Expand All @@ -89,7 +112,15 @@ class TestRHIdentityIntegration:
def test_valid_user_identity(
self, client: TestClient, user_identity_json: dict
) -> None:
"""Test successful request with valid User identity."""
"""Test successful request with valid User identity.

Verify that a GET to /api/v1/conversations with a valid User RH
Identity is accepted.

Sends the provided User identity encoded in the `x-rh-identity` header
and asserts the response status code is `200` (success) or `404` (no
conversations).
"""
headers = {"x-rh-identity": encode_identity(user_identity_json)}

response = client.get("/api/v1/conversations", headers=headers)
Expand Down
23 changes: 21 additions & 2 deletions tests/integration/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@


def read_version_from_pyproject() -> str:
"""Read version from pyproject.toml file."""
"""Read version from pyproject.toml file.

Retrieve the project's version as reported by the PDM tool.

Invokes the `pdm show --version` command and returns the resulting version string
decoded as UTF-8 with surrounding whitespace removed.

Returns:
version (str): The project version reported by PDM.

Raises:
subprocess.CalledProcessError: If the `pdm` command exits with a non-zero status.
"""
# it is not safe to just try to read version from pyproject.toml file directly
# the PDM tool itself is able to retrieve the version, even if the version
# is generated dynamically
Expand All @@ -19,7 +31,14 @@ def read_version_from_pyproject() -> str:


def test_version_handling() -> None:
"""Test how version is handled by the project."""
"""Test how version is handled by the project.

Verify that the package's source __version__ matches the version reported by the project tool.

Raises:
AssertionError: If the source version and the project-reported version
differ; the message includes both versions.
"""
source_version = __version__
project_version = read_version_from_pyproject()
assert (
Expand Down
Loading