"""Test GET /admin/profile-type//profile//resource/.""" import pytest import requests from permissions.constants import constants from tests.integration import config, utils def test_get_all_for_vendor_star_settings_profile(bearer_token_user_with_vendor_star): """Test getting all resources for a user's settings profile with vendor * access.""" profile_id = utils.OWS_ACCOUNT_TEST_USER_SETTINGS_PROFILE_ID profile_type = constants.SETTINGSPROFILE res = requests.get( f'{config.QA_BASE_URL}/admin/profile-type/{profile_type}' f'/profile/{profile_id}/resource/all', headers={ 'Authorization': f'Bearer {bearer_token_user_with_vendor_star}', 'Orchard-Profile-Type': profile_type, 'Orchard-Profile-Id': profile_id, 'Orchard-Identity-Id': utils.OWS_ACCOUNT_TEST_USER_ID, }, ) assert res.status_code == 200 assert next( item for item in res.json()['items'] if item['id'] == '*' and item['type'] == 'Vendor' ) def test_get_all_for_non_vendor_star_settings_profile(bearer_token_user_with_vendor_star): """Test getting all resources for a user's settings profile without vendor * access.""" # OWS_ACCOUNT_TEST_USER is calling to get the resources of OWS_PERMISSIONS_TEST_USER profile_id = utils.OWS_PERMISSIONS_TEST_USER_SETTINGS_PROFILE_ID profile_type = constants.SETTINGSPROFILE res = requests.get( f'{config.QA_BASE_URL}/admin/profile-type/{profile_type}' f'/profile/{profile_id}/resource/all', headers={ 'Authorization': f'Bearer {bearer_token_user_with_vendor_star}', 'Orchard-Profile-Type': profile_type, 'Orchard-Profile-Id': utils.OWS_ACCOUNT_TEST_USER_SETTINGS_PROFILE_ID, 'Orchard-Identity-Id': utils.OWS_ACCOUNT_TEST_USER_ID, }, ) assert res.status_code == 200 assert next( item for item in res.json()['items'] # Platform Test Vendor if item['uuid'] == '2e79b9b8-29ed-44e1-832f-2aa3b47f13c8' and item['type'] == 'Vendor' ) assert next( item for item in res.json()['items'] # LabelParticipant under Columbia Records Group that user has admin access to if item.get('id') == 1712307287807 and item['type'] == 'LabelParticipant' ) @pytest.mark.parametrize( ['profile_type', 'profile_id'], [ # Insights/label profiles of ows-permissions-integration-test-no-settings@sonymusic-pde.com [constants.INSIGHTSPROFILE, 465771], [constants.LABELPROFILE, 10017403], ], ) def test_get_for_other_profiles(profile_type, profile_id, bearer_token_user_with_vendor_star): """Test getting a user's resources for other types of profiles.""" res = requests.get( f'{config.QA_BASE_URL}/admin/profile-type/{profile_type}' f'/profile/{profile_id}/resource/all', headers={ 'Authorization': f'Bearer {bearer_token_user_with_vendor_star}', 'Orchard-Profile-Type': constants.SETTINGSPROFILE, 'Orchard-Profile-Id': utils.OWS_ACCOUNT_TEST_USER_SETTINGS_PROFILE_ID, 'Orchard-Identity-Id': utils.OWS_ACCOUNT_TEST_USER_ID, }, ) assert res.status_code == 200 assert next( item for item in res.json()['items'] # Both profiles have access to Frenchkiss if item.get('id') == 6971 and item['type'] == 'Vendor' ) def test_get_for_invalid_profile(bearer_token_user_with_vendor_star): """Test getting resources with a nonexistent profile id.""" # Just some random number that hopefully won't be a profile id profile_id = 500600700 res = requests.get( f'{config.QA_BASE_URL}/admin/profile-type/{constants.LABELPROFILE}' f'/profile/{profile_id}/resource/all', headers={ 'Authorization': f'Bearer {bearer_token_user_with_vendor_star}', 'Orchard-Profile-Type': constants.SETTINGSPROFILE, 'Orchard-Profile-Id': utils.OWS_ACCOUNT_TEST_USER_SETTINGS_PROFILE_ID, 'Orchard-Identity-Id': utils.OWS_ACCOUNT_TEST_USER_ID, }, ) assert res.status_code == 200 assert len(res.json()['items']) == 0