"""Test ows-royalties requests.""" from unittest.mock import patch import httpx from owsclient.test import OwsClientMock from reserves_take.constants import constants from reserves_take.ows_royalties import get_accounting_period_by_id from reserves_take.ows_royalties import get_accounting_run_by_id from reserves_take.ows_royalties import get_contract_ids_by_accounting_run @patch('reserves_take.ows_royalties.raise_service_error') @patch('reserves_take.ows_royalties.app_logger') def test_get_accounting_run_by_id( mock_logger, mock_raise_service_error, mock_accounting_run_response, ows_client_mock: OwsClientMock, ): """Test successfully getting accounting run for the specified accounting run id.""" accounting_run_id = 1 ows_client_mock.get( 'ows-royalties', f'/accounting-run/{accounting_run_id}', ).mock( return_value=httpx.Response( 200, json=mock_accounting_run_response ) ) res = get_accounting_run_by_id(accounting_run_id) assert res assert res == mock_accounting_run_response mock_logger.info.assert_called_once_with( constants.GET_ACCOUNTING_RUN_MSG.format(accounting_run_id) ) mock_logger.error.assert_not_called() mock_raise_service_error.assert_not_called() @patch('reserves_take.ows_royalties.raise_service_error') @patch('reserves_take.ows_royalties.app_logger') def test_get_accounting_period_by_id( mock_logger, mock_raise_service_error, mock_accounting_period_response, ows_client_mock: OwsClientMock, ): """Test successfully getting accounting period for the specified id.""" accounting_period_id = 1 ows_client_mock.get( 'ows-royalties', f'/accounting-period/{accounting_period_id}', ).mock( return_value=httpx.Response( 200, json=mock_accounting_period_response ) ) res = get_accounting_period_by_id(accounting_period_id) assert res assert res == mock_accounting_period_response mock_logger.info.assert_called_once_with( constants.GET_ACCOUNTING_PERIOD_MSG.format(accounting_period_id) ) mock_logger.error.assert_not_called() mock_raise_service_error.assert_not_called() @patch('reserves_take.ows_royalties.raise_service_error') @patch('reserves_take.ows_royalties.app_logger') def test_get_contract_ids_by_accounting_run( mock_logger, mock_raise_service_error, mock_contract_ids_response, ows_client_mock: OwsClientMock, ): """Test successfully getting contract_id for the specified accounting run id.""" accounting_run_id = 1 ows_client_mock.get( 'ows-royalties', f'/accounting-run/{accounting_run_id}/run-controller/contracts', ).mock( return_value=httpx.Response( 200, json=mock_contract_ids_response ) ) res = get_contract_ids_by_accounting_run(accounting_run_id) assert res assert res == mock_contract_ids_response mock_logger.info.assert_called_once_with( constants.GET_CONTRACTS_MSG.format(accounting_run_id) ) mock_logger.error.assert_not_called() mock_raise_service_error.assert_not_called()