"""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 PdpAuthorizationBackend from product_digital import config from product_digital.api import ( authorization_backend, ows_client, setup_authorization_backend, setup_ows_client, ) @patch('product_digital.api.OwsClient') def test_setup_ows_client_calls_constructor_with_config(mock_ows_client_class): """Verify setup_ows_client calls OwsClient constructor with config values.""" setup_ows_client() mock_ows_client_class.assert_called_once_with( config.ENVIRONMENT, config.SERVICE_NAME, correlation_id_getter=correlation_id_getter, request_context_getter=request_context_getter, ) def test_setup_ows_client_returns_ows_client_instance(): """Verify setup_ows_client returns an OwsClient instance.""" result = setup_ows_client() assert isinstance(result, OwsClient) @patch('product_digital.api.PdpAuthorizationBackend') @patch('product_digital.api.OwsPdpClient') def test_setup_authorization_backend_wraps_ows_client_in_pdp_client(mock_pdp_client, mock_pdp_backend): """Verify setup_authorization_backend wraps the ows_client in OwsPdpClient and PdpAuthorizationBackend.""" mock_ows_client = MagicMock() result = setup_authorization_backend(mock_ows_client) mock_pdp_client.assert_called_once_with(mock_ows_client) mock_pdp_backend.assert_called_once_with(mock_pdp_client.return_value) assert result is mock_pdp_backend.return_value def test_module_level_globals_are_correct_types(): """Verify module-level globals are instances of the expected types.""" assert isinstance(ows_client, OwsClient) assert isinstance(authorization_backend, PdpAuthorizationBackend)