"""Tests for reference_sap_profit_center 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_contract.blueprints.reference_sap_profit_center.pdp_authorize_resource') @patch('abacus_contract.blueprints.reference_sap_profit_center.ItemView.get') def test_get_reference_sap_profit_center_by_id( mock_super_get: MagicMock, mock_pdp_authorize_resource: MagicMock, fixture_client: FlaskClient, profile_type: str, profile_role: str, authorize_return: bool, expected_status: int ): """Test successfully retrieving reference sap profit center by id.""" mock_response = flaskify(response.Response( message={ 'reference_sap_profit_center_id': 1, 'business_group': 'ORC', 'company_code': '3', 'profit_center': 'UK4914', }, status=200 )) mock_super_get.return_value = mock_response mock_pdp_authorize_resource.return_value = authorize_return res = fixture_client.get( '/reference-sap-profit-center/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_pdp_authorize_resource.assert_called_once_with( 1, 'reference_sap_profit_center' ) else: mock_pdp_authorize_resource.assert_not_called()