Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

from pathlib import Path

from typing import Generator
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.engine import Engine

from configuration import configuration
from models.database.base import Base


@pytest.fixture(autouse=True)
def reset_configuration_state():
def reset_configuration_state() -> Generator:
"""Reset configuration state before each integration test.

This autouse fixture ensures test independence by resetting the
Expand All @@ -25,7 +27,7 @@ def reset_configuration_state():


@pytest.fixture(name="test_config", scope="function")
def test_config_fixture():
def test_config_fixture() -> Generator:
"""Load real configuration for integration tests.

This fixture loads the actual configuration file used in testing,
Expand All @@ -44,7 +46,7 @@ def test_config_fixture():


@pytest.fixture(name="test_db_engine", scope="function")
def test_db_engine_fixture():
def test_db_engine_fixture() -> Generator:
"""Create an in-memory SQLite database engine for testing.

This provides a real database (not mocked) for integration tests.
Expand All @@ -68,7 +70,7 @@ def test_db_engine_fixture():


@pytest.fixture(name="test_db_session", scope="function")
def test_db_session_fixture(test_db_engine):
def test_db_session_fixture(test_db_engine: Engine) -> Generator[Session, None, None]:
"""Create a database session for testing.

Provides a real database session connected to the in-memory test database.
Expand Down
34 changes: 25 additions & 9 deletions tests/integration/endpoints/test_info_integration.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
"""Integration tests for the /info endpoint."""

from typing import Generator, Any
import pytest
from pytest_mock import MockerFixture, AsyncMockType

from fastapi import HTTPException, Request, status
from llama_stack_client import APIConnectionError
from llama_stack_client.types import VersionInfo

from configuration import AppConfig
from app.endpoints.info import info_endpoint_handler
from authentication.noop import NoopAuthDependency
from version import __version__


@pytest.fixture(name="mock_llama_stack_client")
def mock_llama_stack_client_fixture(mocker):
def mock_llama_stack_client_fixture(
mocker: MockerFixture,
) -> Generator[Any, None, None]:
"""Mock only the external Llama Stack client.

This is the only external dependency we mock for integration tests,
Expand All @@ -31,7 +37,7 @@ def mock_llama_stack_client_fixture(mocker):


@pytest.fixture(name="test_request")
def test_request_fixture():
def test_request_fixture() -> Request:
"""Create a test FastAPI Request object with proper scope."""
return Request(
scope={
Expand All @@ -43,7 +49,7 @@ def test_request_fixture():


@pytest.fixture(name="test_auth")
async def test_auth_fixture(test_request):
async def test_auth_fixture(test_request: Request) -> tuple[str, str, bool, str]:
"""Create authentication using real noop auth module.

This uses the actual NoopAuthDependency instead of mocking,
Expand All @@ -55,8 +61,11 @@ async def test_auth_fixture(test_request):

@pytest.mark.asyncio
async def test_info_endpoint_returns_service_information(
test_config, mock_llama_stack_client, test_request, test_auth
):
test_config: AppConfig,
mock_llama_stack_client: AsyncMockType,
test_request: Request,
test_auth: tuple[str, str, bool, str],
) -> None:
"""Test that info endpoint returns correct service information.

This integration test verifies:
Expand Down Expand Up @@ -88,8 +97,12 @@ async def test_info_endpoint_returns_service_information(

@pytest.mark.asyncio
async def test_info_endpoint_handles_connection_error(
test_config, mock_llama_stack_client, test_request, test_auth, mocker
):
test_config: AppConfig,
mock_llama_stack_client: AsyncMockType,
test_request: Request,
test_auth: tuple[str, str, bool, str],
mocker: MockerFixture,
) -> None:
"""Test that info endpoint properly handles Llama Stack connection errors.

This integration test verifies:
Expand Down Expand Up @@ -124,8 +137,11 @@ async def test_info_endpoint_handles_connection_error(

@pytest.mark.asyncio
async def test_info_endpoint_uses_configuration_values(
test_config, mock_llama_stack_client, test_request, test_auth
):
test_config: AppConfig,
mock_llama_stack_client: AsyncMockType,
test_request: Request,
test_auth: tuple[str, str, bool, str],
) -> None:
"""Test that info endpoint correctly uses configuration values.

This integration test verifies:
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_openapi_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def open_api_spec() -> dict:
return _load_openapi_spec()


def test_openapi_top_level_info(spec: dict):
def test_openapi_top_level_info(spec: dict) -> None:
"""Test all top level informations stored in OpenAPI specification."""
assert spec.get("openapi") == "3.1.0"

Expand All @@ -48,7 +48,7 @@ def test_openapi_top_level_info(spec: dict):
assert "apache.org/licenses" in (license_info.get("url") or "")


def test_servers_section_present(spec: dict):
def test_servers_section_present(spec: dict) -> None:
"""Test the servers section stored in OpenAPI specification."""
servers = spec.get("servers")
assert isinstance(servers, list) and servers, "servers must be a non-empty list"
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_servers_section_present(spec: dict):
)
def test_paths_and_responses_exist(
spec: dict, path: str, method: str, expected_codes: set[str]
):
) -> None:
"""Tests all paths defined in OpenAPI specification."""
paths = spec.get("paths") or {}
assert path in paths, f"Missing path: {path}"
Expand Down
Loading