"""Test the GET /v2/identity//tenants endpoint.""" from unittest.mock import MagicMock import requests from permissions.constants.constants import VENDOR_STAR_UUID from tests.integration import config, utils def test_unauthenticated(): """Integration test for no jwt.""" response = requests.get( f'{config.QA_BASE_URL}/v2/identity//tenants', ) assert response.status_code == 401 def test_unauthorized(bearer_token_user_without_settings): """Integration test for no settings profile.""" response = requests.get( f'{config.QA_BASE_URL}/v2/identity//tenants', headers={'Authorization': f'Bearer {bearer_token_user_without_settings}'}, ) assert response.status_code == 403 def test_employee_admin_sees_all_tenants(bearer_token_user_with_vendor_star): """Integration test for an admin with vendor * getting a user's tenants.""" response = requests.get( f'{config.QA_BASE_URL}/v2/identity/{utils.NO_SETTINGS_USER_ID}/tenants', headers={'Authorization': f'Bearer {bearer_token_user_with_vendor_star}'}, ) assert response.status_code == 200 tenants = response.json()['tenants'] # "Test Label" vendor vendor1 = next(t for t in tenants if t['tenant_uuid'] == '573d0372-7f2f-48a6-8deb-c9a6558f9549') assert vendor1['tenant_type'] == 'account' assert vendor1['roles'] == ['COLLABORATORS_BASE_ROLE'] # Frenchkiss vendor2 = next(t for t in tenants if t['tenant_uuid'] == 'fff741c2-6def-4493-bfdf-c2bcb1128e02') assert vendor2['tenant_type'] == 'account' assert sorted(vendor2['roles']) == [ 'COLLABORATORS_BASE_ROLE', 'INSIGHTS_BASE_ROLE', 'WORKSTATION_ADVERTISING_ROLE', 'WORKSTATION_ANALYTICS_BASE_ROLE', 'WORKSTATION_CATALOG_ROLE', 'WORKSTATION_MARKETING_ROLE', ] def test_non_employee_admin_sees_some_tenants(bearer_token): """Integration test for an admin without vendor * getting a user's tenants.""" response = requests.get( f'{config.QA_BASE_URL}/v2/identity/{utils.NO_SETTINGS_USER_ID}/tenants', headers={'Authorization': f'Bearer {bearer_token}'}, ) assert response.status_code == 200 assert response.json() == { 'tenants': [ # These two users only have the "Test Label" vendor in common { 'tenant_uuid': '573d0372-7f2f-48a6-8deb-c9a6558f9549', 'tenant_type': 'account', 'roles': ['COLLABORATORS_BASE_ROLE'], } ] } def test_admin_sees_audience_profile_roles(bearer_token_user_with_vendor_star): """Integration test for an admin getting a user's fansifter roles.""" # User fansifter_test_1@sonymusic-pde.com' identity_id = 'ad8135ca-e000-4e59-8a12-c6b56fb0dad7' response = requests.get( f'{config.QA_BASE_URL}/v2/identity/{identity_id}/tenants', headers={'Authorization': f'Bearer {bearer_token_user_with_vendor_star}'}, ) assert response.status_code == 200 assert next( tenant for tenant in response.json()['tenants'] if tenant['tenant_type'] == 'account' and 'fansifter_can_view_fan_data' in tenant['roles'] ) def test_employee_sees_other_employee_tenant_without_vendor_star( bearer_token_user_with_vendor_star: MagicMock, ) -> None: """Test for an admin with vendor * getting another employee's tenants.""" response = requests.get( f'{config.QA_BASE_URL}/v2/identity/{utils.TEST_EMPLOYEE_USER_ID}/tenants', headers={'Authorization': f'Bearer {bearer_token_user_with_vendor_star}'}, ) assert response.status_code == 200 tenants = response.json()['tenants'] tenant_uuids = [uuid for uuid in [t['tenant_uuid'] for t in tenants]] assert VENDOR_STAR_UUID not in tenant_uuids