"""Test Account Tax Info History handlers.""" from unittest.mock import MagicMock, patch from flask.testing import FlaskClient from owsresponse import response 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.account_tax_info_history.authorize_many_accounts') @patch('abacus_account.blueprints.account_tax_info_history.logic') def test_get_account_tax_info_history( mock_logic: MagicMock, mock_authorize_many_accounts: MagicMock, fixture_client: FlaskClient, profile_type: str, profile_role: str, authorize_return: bool, expected_status: int): """Test to get account_tax_info_history by an account_id.""" mock_response = response.Response(message={'result': 'ok'}, status=200) mock_logic.get_account_tax_info_history.return_value = mock_response mock_authorize_many_accounts.return_value = authorize_return res = fixture_client.get( '/account/1/account-tax-info-history', 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.get_account_tax_info_history.assert_called_once_with(1) if authorize_return is not None: mock_authorize_many_accounts.assert_called_once_with([1]) else: mock_authorize_many_accounts.assert_not_called()