"""Unit tests for reference_flowthrough_calculation endpoints.""" from unittest.mock import MagicMock, patch import pytest from flask import testing as flask_testing from abacus_contract.tests.utils import factories @pytest.mark.parametrize( ('standalone_check_result', 'pdp_check_result', 'expected_status'), [ pytest.param(True, None, 200, id='Standalone check pass'), pytest.param(False, False, 403, id='PDP check fail'), pytest.param(False, True, 200, id='PDP check pass'), ], ) @patch('abacus_contract.blueprints.reference_flowthrough_calculation.authorization') @patch('abacus_contract.blueprints.reference_flowthrough_calculation.flask_request') def test_get_reference_flowthrough_calculation_authorization( mock_flask_request: MagicMock, mock_authorization: MagicMock, standalone_check_result: bool, pdp_check_result: bool | None, expected_status: int, fixture_client: flask_testing.FlaskClient, ) -> None: """Test authorization for getting reference payment type by id.""" mock_flask_request.verify_rules_access_standalone.return_value = ( standalone_check_result ) mock_authorization.pdp_authorize_resource.return_value = pdp_check_result reference_flowthrough_calculation = ( factories.ReferenceFlowthroughCalculationFactory() ) reference_flowthrough_calculation_id = ( reference_flowthrough_calculation.reference_flowthrough_calculation_id ) res = fixture_client.get( f'/reference-flowthrough-calculation/{reference_flowthrough_calculation_id}' ) assert res.status_code == expected_status mock_flask_request.verify_rules_access_standalone.assert_called_once() if standalone_check_result: mock_authorization.pdp_authorize_resource.assert_not_called() else: mock_authorization.pdp_authorize_resource.assert_called_once_with( resource_id=0, resource_type='reference_flowthrough_calculation', )