"""Tests ows-abacus-account requests.""" from datetime import datetime from typing import Any import httpx import pytest from owsclient.test import OwsClientMock from sync_contract_sap.error_handling import OwsServiceException from sync_contract_sap.ows_abacus_account import ( get_sap_formatted_account, update_account_sap_created_at, ) def test_get_sap_formatted_account_by_id( mock_sap_formatted_account: dict[str, Any], ows_client_mock: OwsClientMock, ) -> None: """Test get_sap_formatted_account. success case """ account_id = 1 request_url = f'/account/{account_id}/sap' ows_client_mock.get('ows-abacus-account', request_url).mock( return_value=httpx.Response(200, json=mock_sap_formatted_account) ) res = get_sap_formatted_account(account_id) assert res == mock_sap_formatted_account def test_get_sap_formatted_account_by_id_failure( ows_client_mock: OwsClientMock, ) -> None: """Test get_sap_formatted_account raises on non-200 response.""" account_id = 1 request_url = f'/account/{account_id}/sap' ows_client_mock.get('ows-abacus-account', request_url).mock( return_value=httpx.Response(400, json='error') ) with pytest.raises( OwsServiceException, match=f'ERROR in GET /account/{account_id}/sap' ): get_sap_formatted_account(account_id) def test_update_account_sap_created_at( mock_account: dict[str, Any], ows_client_mock: OwsClientMock, ) -> None: """Test update_account_sap_created_at. success case """ account_id = 11 ows_client_mock.put('ows-abacus-account', f'/account/{account_id}').mock( return_value=httpx.Response(200, json=mock_account) ) res = update_account_sap_created_at( account_id, datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f%z') ) assert res == mock_account def test_update_account_sap_created_at_failure( ows_client_mock: OwsClientMock, ) -> None: """Test update_account_sap_created_at raises on non-200 response.""" account_id = 11 ows_client_mock.put('ows-abacus-account', f'/account/{account_id}').mock( return_value=httpx.Response(400, json='error') ) with pytest.raises( OwsServiceException, match=f'ERROR in PUT /account/{account_id}' ): update_account_sap_created_at( account_id, datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f%z') )