"""Tests for API factory functions.""" from unittest.mock import MagicMock, patch from owsclient import OwsClient from owsrequest.ows_client import correlation_id_getter, request_context_getter from python_pdp_sdk.backends.authorization_backend import AuthorizationBackend from assets import config from assets.api import ( authorization_backend, ows_client, setup_authorization_backend, setup_ows_client, ) @patch("assets.api.OwsClient") def test_setup_ows_client_calls_constructor_with_config( mock_ows_client: MagicMock, ) -> None: """Verify setup_ows_client calls the OwsClient constructor with config values.""" setup_ows_client() mock_ows_client.assert_called_once_with( environment=config.ENVIRONMENT, service_name=config.SERVICE_NAME, correlation_id_getter=correlation_id_getter, request_context_getter=request_context_getter, ) def test_setup_ows_client_returns_ows_client_instance() -> None: """Verify setup_ows_client returns an OwsClient instance.""" assert isinstance(setup_ows_client(), OwsClient) @patch("assets.api.PdpAuthorizationBackend") @patch("assets.api.OwsPdpClient") def test_setup_authorization_backend_wraps_ows_client_in_pdp_client( mock_ows_pdp_client: MagicMock, mock_pdp_authorization_backend: MagicMock, ) -> None: """Verify ows_client is wrapped in OwsPdpClient and PdpAuthorizationBackend.""" mock_ows_client = MagicMock() result = setup_authorization_backend(mock_ows_client) mock_ows_pdp_client.assert_called_once_with(mock_ows_client) mock_pdp_authorization_backend.assert_called_once_with( mock_ows_pdp_client.return_value ) assert result is mock_pdp_authorization_backend.return_value def test_module_level_globals_satisfy_expected_interfaces() -> None: """Verify the module-level globals satisfy their expected interfaces.""" assert isinstance(ows_client, OwsClient) assert isinstance(authorization_backend, AuthorizationBackend)