"""Test for ows-store model.""" from unittest.mock import MagicMock import pytest from oto import status as http_status from owsrequest import request as requests from timed_release.models import ows_store as store @pytest.mark.parametrize( 'request_headers', [ { # Test case: with identity headers 'Orchard-Identity-Id': 1234, 'Orchard-Profile-Id': 123, 'Orchard-Profile-Type': 'OrchAdminProfile' }, { # Test case: with JWT Authorization header 'Authorization': 'Bearer test_token', 'Orchard-Profile-Id': 123, 'Orchard-Profile-Type': 'OrchAdminProfile' } ], ) def test_get_stores_success(monkeypatch, stores_fixture, request_headers): """Test get stores success case.""" ows_store_response = MagicMock() ows_store_response.status_code = http_status.OK ows_store_response.json = MagicMock(return_value=stores_fixture) mock_get = MagicMock(return_value=ows_store_response) monkeypatch.setattr(requests, 'get', mock_get) response = store.get_stores(request_headers) mock_get.assert_called_once_with( 'ows-store', '/stores', params={'status': ['active']}, headers=request_headers ) assert response.status == http_status.OK assert response.message == stores_fixture['items'] def test_get_stores_failure(monkeypatch, stores_fixture): """Test get stores failure case.""" request_headers = { 'Orchard-Identity-Id': 1234, 'Orchard-Profile-Id': 123, 'Orchard-Profile-Type': 'OrchAdminProfile' } error_dict = {'error': 'internal error'} ows_store_response = MagicMock() ows_store_response.status_code = http_status.INTERNAL_ERROR ows_store_response.text = MagicMock(return_value=error_dict) mock_get = MagicMock(return_value=ows_store_response) monkeypatch.setattr(requests, 'get', mock_get) response = store.get_stores(request_headers) mock_get.assert_called_once_with( 'ows-store', '/stores', params={'status': ['active']}, headers=request_headers ) assert response.status == http_status.INTERNAL_ERROR