"""Tests for accounting period report handlers.""" from unittest.mock import patch from owsresponse import response from royalties.constants.constants import REPORT_TYPE @patch('royalties.blueprints.accounting_period_report.logic') def test_get_acc_period_reports_by_acc_period_id(mock_logic, fixture_client): """Test to get accounting period reports by an accounting_period_id.""" mock_response = response.Response(message='ok', status=200) mock_logic.get_acc_period_reports_by_acc_period_id.return_value = mock_response accounting_period_id = 1234 res = fixture_client.get( f'/accounting-period/{accounting_period_id}/accounting-period-reports' ) assert res.status_code == 200 mock_logic.get_acc_period_reports_by_acc_period_id.assert_called_once_with( accounting_period_id ) @patch('royalties.blueprints.accounting_period_report.logic') def test_get_acc_period_report(mock_logic, fixture_client): """Test to get accounting period reports by an accounting_period_id and report_type.""" mock_response = response.Response(message='ok', status=200) mock_logic.get_acc_period_report.return_value = mock_response accounting_period_id = 1234 report_type = REPORT_TYPE.VAT_EXEMPT res = fixture_client.get( f'/accounting-period/{accounting_period_id}/report-type/{report_type}/accounting-period-report' ) assert res.status_code == 200 mock_logic.get_acc_period_report.assert_called_once_with( accounting_period_id, report_type ) @patch('royalties.blueprints.accounting_period_report.logic') def test_create_or_update_acc_period_report(mock_logic, fixture_client): """Test to check accounting period report's creation blueprint .""" mock_response = response.Response(message='ok', status=201) mock_logic.create_or_update_accounting_period_report.return_value = mock_response accounting_period_id = 1 report_type = REPORT_TYPE.VAT_EXEMPT report_export_url = 's3://some/report/url' res = fixture_client.post( f'/accounting-period/{accounting_period_id}/accounting-period-report', json={'report_type': report_type, 'report_export_url': report_export_url}, ) assert res.status_code == 201 mock_logic.create_or_update_accounting_period_report.assert_called_once_with( accounting_period_id=accounting_period_id, report_type=report_type, report_export_url=report_export_url, )