diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 066e110af..74f875fe2 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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 @@ -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, @@ -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. @@ -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. diff --git a/tests/integration/endpoints/test_info_integration.py b/tests/integration/endpoints/test_info_integration.py index 32222dfbd..3d7ead15c 100644 --- a/tests/integration/endpoints/test_info_integration.py +++ b/tests/integration/endpoints/test_info_integration.py @@ -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, @@ -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={ @@ -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, @@ -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: @@ -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: @@ -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: diff --git a/tests/integration/test_openapi_json.py b/tests/integration/test_openapi_json.py index 166fc00c0..6bdbdcbce 100644 --- a/tests/integration/test_openapi_json.py +++ b/tests/integration/test_openapi_json.py @@ -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" @@ -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" @@ -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}"