"""Unit tests for Payoneer Program 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_payoneer_program.' 'authorize_resource') @patch('abacus_account.blueprints.reference_payoneer_program.' 'ItemView.get') def test_get_reference_payoneer_program_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 for getting a reference_payoneer_program by id.""" mock_response = flaskify(response.Response( message={ 'payoneer_program_id': 1, 'payoneer_program_name': 'test', 'funding_currency': 'USD' }, status=200 )) mock_super_get.return_value = mock_response mock_authorize_resource.return_value = authorize_return res = fixture_client.get( '/payoneer-program/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, 'payoneer_program') else: mock_authorize_resource.assert_not_called()