"""Unit testcases for ows-abacus-worksheet requests.""" from unittest.mock import patch import httpx from owsclient.test import OwsClientMock from correction_apply.ows_abacus_worksheet import get_unapplied_worksheet_corrections @patch('correction_apply.ows_abacus_worksheet.raise_service_error') def test_get_unapplied_worksheet_corrections( mock_raise_service_error, mock_worksheet_correction, ows_client_mock: OwsClientMock, ): """Test successfully getting worksheet corrections.""" statement_period_id = 2 correction_type = 'royalty_reversal' request_url = f'/worksheet-correction/statement-period/{statement_period_id}/{correction_type}/unapplied?limit=1&offset=0' # noqa: E501 ows_client_mock.get('ows-abacus-worksheet', request_url).mock( return_value=httpx.Response( 200, json={'items': [mock_worksheet_correction], 'total_count': 1} ) ) res = get_unapplied_worksheet_corrections( correction_type, statement_period_id, 1, 0 ) assert res['items'] == [mock_worksheet_correction] mock_raise_service_error.assert_not_called() @patch('correction_apply.ows_abacus_worksheet.raise_service_error') def test_get_unapplied_worksheet_corrections_failure( mock_raise_service_error, ows_client_mock: OwsClientMock, ): """Test failure getting worksheet corrections.""" statement_period_id = 2 correction_type = 'royalty_reversal' request_url = f'/worksheet-correction/statement-period/{statement_period_id}/{correction_type}/unapplied' # noqa: E501 ows_client_mock.get('ows-abacus-worksheet', request_url).mock( return_value=httpx.Response( 400, text='mock error', ) ) res = get_unapplied_worksheet_corrections( correction_type, statement_period_id, 1, 0 ) assert res is None mock_raise_service_error.assert_called_once_with( f'ERROR in GET {request_url}', 'ows-abacus-worksheet' )