"""Tests for ows-abacus-account related requests.""" from unittest.mock import patch import httpx from owsclient.test import OwsClientMock import config from sync_contract.ows_abacus_account import get_account_payment_terms @patch('sync_contract.ows_abacus_account.app_logger') @patch('sync_contract.ows_abacus_account.raise_service_error') def test_get_account_payment_terms( mock_raise_service_error, mock_logger, mock_account_payment_terms, ows_client_mock: OwsClientMock, ): """Test to successfully get account payment terms.""" account_id = mock_account_payment_terms['account_id'] ows_client_mock.get( 'ows-abacus-account', f'/account/{account_id}/account-payment-term/' ).mock( return_value=httpx.Response( 200, json=mock_account_payment_terms, ) ) result = get_account_payment_terms(account_id) assert result == mock_account_payment_terms mock_logger.info.assert_called_once_with( config.MESSAGE_GET_ACCOUNT_PAYMENT_TERMS.format(account_id) ) mock_raise_service_error.assert_not_called() @patch('sync_contract.ows_abacus_account.app_logger') @patch('sync_contract.ows_abacus_account.raise_service_error') def test_get_account_payment_terms_error( mock_raise_service_error, mock_logger, ows_client_mock: OwsClientMock, ): """Test to raise an exception on error response.""" account_id = 1 ows_client_mock.get( 'ows-abacus-account', f'/account/{account_id}/account-payment-term/' ).mock( return_value=httpx.Response( 400, json={'error': 'Error'}, ) ) result = get_account_payment_terms(account_id) assert result is None mock_logger.info.assert_called_once_with( config.MESSAGE_GET_ACCOUNT_PAYMENT_TERMS.format(account_id) ) mock_raise_service_error.assert_called_once_with( 'ERROR in GET /account/1/account-payment-term/', 'ows-abacus-account' )