"""Test GET /users/identity//application//profiles endpoint.""" import pytest import requests from tests.integration import config, conftest @pytest.mark.parametrize( ('profile_payload', 'app_name'), [ ( { 'profile_name': 'Test InsightsProfile', 'profile_type': 'InsightsProfile', 'roles': ['catalog'], }, 'frontend-insights', ), ( { 'profile_name': 'Test InsightsProfile', 'profile_type': 'InsightsProfile', 'roles': ['catalog'], }, # This should give you back the insights profile like above 'orchard-go', ), ( { 'profile_name': 'Test LabelProfile', 'profile_type': 'LabelProfile', 'roles': ['marketing'], }, 'workstation', ), ], ) def test_get_profile_by_app_name(profile_payload, app_name, new_identity, grass_headers): """Test getting a profile by app name.""" identity_id = new_identity['id'] # Create a profile for this user profile = conftest.create_profile_for_identity_id( headers=grass_headers, profile_payload=profile_payload, identity_id=identity_id, ) # Now assume their identity (headers must match the user whose profile you're getting) new_identity_headers = conftest.create_grass_headers( identity_id=identity_id, identity_uuid=identity_id, profile_type=profile['profile_type'], profile_id=str(profile['profile_id']), ) res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}/application/{app_name}/profiles', headers=new_identity_headers, ) assert res.status_code == 200 body = res.json() assert 'items' in body assert 'pagination' in body fetched_profile = body['items'][0] for key, value in profile.items(): assert fetched_profile[key] == value def test_get_nonexistent_profile_by_app_name(new_identity): """Test attempting to get a nonexistent profile by app name.""" identity_id = new_identity['id'] new_identity_headers = conftest.create_grass_headers( identity_id=identity_id, identity_uuid=identity_id, profile_type='SettingsProfile', profile_id='its-not-like-we-check', ) app_name = 'workstation' res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}/application/{app_name}/profiles', headers=new_identity_headers, ) assert res.status_code == 200 body = res.json() assert 'items' in body assert 'pagination' in body assert body['items'] == []