"""Test ows-royalties requests.""" from unittest.mock import patch import httpx from owsclient.test import OwsClientMock from ledger_accounting_run_balance.constants.constants import GET_ACCOUNTING_PERIOD_MSG from ledger_accounting_run_balance.ows_royalties import \ get_accounting_period_by_accounting_run_id @patch('ledger_accounting_run_balance.ows_royalties.raise_service_error') @patch('ledger_accounting_run_balance.ows_royalties.app_logger') def test_get_accounting_period_by_accounting_run_id_success( mock_logger, mock_raise_service_error, ows_client_mock: OwsClientMock ): """Test successfully getting accounting period for the accounting run.""" accounting_run_id = 1 mock_response = { 'accounting_period_status': 'open', 'closed_date': None, 'contract_type': 'neighbouring_rights', 'accounting_period_name': 'test', 'statement_period_id': 282, 'accounting_period_id': 1 } ows_client_mock.get( 'ows-royalties', f'/accounting-run/{accounting_run_id}/accounting-period' ).mock( return_value=httpx.Response( 200, json=mock_response ) ) res = get_accounting_period_by_accounting_run_id(accounting_run_id) assert res assert res == mock_response mock_logger.info.assert_called_once_with( GET_ACCOUNTING_PERIOD_MSG.format(accounting_run_id) ) mock_raise_service_error.assert_not_called()