"""Tests for account_payment_term handlers.""" from unittest.mock import MagicMock, patch from flask.testing import FlaskClient from owsresponse import response from owsresponse.adaptors.flask import flaskify import pytest @pytest.mark.parametrize( ( 'profile_type', 'profile_role', 'authorize_return', 'expected_status' ), [ pytest.param( 'AbacusProfile', 'administrator', None, 200, id='standalone check' ), pytest.param( 'Account360Profile', 'account360', True, 200, id='pdp check, authorized' ), pytest.param( 'Account360Profile', 'account360', False, 403, id='pdp check, unauthorized' ) ] ) @patch('abacus_account.blueprints.reference_agreement_type.authorize_resource') @patch('abacus_account.blueprints.reference_agreement_type.get_agreement_types') def test_get_reference_agreement_types( mock_logic, mock_authorize_resource: MagicMock, fixture_client: FlaskClient, profile_type: str, profile_role: str, authorize_return: bool, expected_status: int ): """Test successful retrieving reference agreement types.""" mock_logic.return_value = response.Response(message=[ { 'reference_agreement_type_id': 1, 'agreement_type': 'Test 1' }, { 'reference_agreement_type_id': 2, 'agreement_type': 'Test 2' }, ], status=200) mock_authorize_resource.return_value = authorize_return res = fixture_client.get( '/reference-agreement-types', headers={ 'Orchard-Requestor-Service': 'graphql-abacus', 'Orchard-Profile-Type': profile_type, 'Orchard-Profile-Id': '1234', 'Orchard-Roles': profile_role, 'Orchard-Identity-Id': '1234' } ) assert res.status_code == expected_status if expected_status == 200: mock_logic.assert_called_once() if authorize_return is not None: mock_authorize_resource.assert_called_once_with(0, 'reference_agreement_type') else: mock_authorize_resource.assert_not_called() @pytest.mark.parametrize( ( 'profile_type', 'profile_role', 'authorize_return', 'expected_status' ), [ pytest.param( 'AbacusProfile', 'administrator', None, 200, id='standalone check' ), pytest.param( 'Account360Profile', 'account360', True, 200, id='pdp check, authorized' ), pytest.param( 'Account360Profile', 'account360', False, 403, id='pdp check, unauthorized' ) ] ) @patch('abacus_account.blueprints.reference_agreement_type.authorize_resource') @patch('abacus_account.blueprints.reference_agreement_type.ItemView.get') def test_get_reference_agreement_type_by_id( mock_super_get: MagicMock, mock_authorize_resource: MagicMock, fixture_client: FlaskClient, profile_type: str, profile_role: str, authorize_return: bool, expected_status: int ): """Test successfully retrieving reference agreement type by id.""" mock_response = flaskify(response.Response( message={ 'reference_agreement_type_id': 1, 'agreement_type': 'Test 1' }, status=200 )) mock_super_get.return_value = mock_response mock_authorize_resource.return_value = authorize_return res = fixture_client.get( '/reference-agreement-type/1', headers={ 'Orchard-Requestor-Service': 'graphql-abacus', 'Orchard-Profile-Type': profile_type, 'Orchard-Profile-Id': '1234', 'Orchard-Roles': profile_role, 'Orchard-Identity-Id': '1234' }) if expected_status == 200: assert res.json == mock_response.json if authorize_return is not None: mock_authorize_resource.assert_called_once_with(1, 'reference_agreement_type') else: mock_authorize_resource.assert_not_called()