"""Tests for the PATCH /profile/profile_id//profile_type/ endpoint.""" import uuid import requests from tests.integration import config def test_update_and_fetch_profile(new_profile, grass_headers): """Test updating and fetching a profile.""" profile_id = new_profile['profile_id'] profile_type = new_profile['profile_type'] patch_body = {'roles': ['analytics', 'administrator'], 'profile_name': '🆕 name'} res = requests.patch( f'{config.QA_BASE_URL}/profile/profile_id/{profile_id}/profile_type/{profile_type}', headers=grass_headers, json=patch_body, ) assert res.status_code == 200 body = res.json() assert body['roles'] == patch_body['roles'] assert body['profile_name'] == patch_body['profile_name'] assert body['profile_id'] == profile_id assert body['profile_type'] == profile_type # Fetch the updated profile 🐩 res = requests.get( f'{config.QA_BASE_URL}/profile/profile_id/{profile_id}/profile_type/{profile_type}', headers=grass_headers, ) assert res.status_code == 200 body = res.json() assert body['roles'] == patch_body['roles'] assert body['profile_name'] == patch_body['profile_name'] assert body['profile_id'] == profile_id assert body['profile_type'] == profile_type def test_update_nonexistent_profile(grass_headers): """Test attempting to update a nonexistent profile.""" patch_body = {'roles': ['analytics', 'administrator'], 'profile_name': '🆕 name'} profile_id = uuid.uuid4() profile_type = 'InsightsProfile' res = requests.patch( f'{config.QA_BASE_URL}/profile/profile_id/{profile_id}/profile_type/{profile_type}', headers=grass_headers, json=patch_body, ) assert res.status_code == 404 body = res.json() assert body['code'] == 'not_found_error' assert body['message'] == 'Profile not found' def test_update_profile_with_invalid_body(new_profile, grass_headers): """Test attempting to update a profile with an invalid body.""" profile_id = new_profile['profile_id'] profile_type = new_profile['profile_type'] patch_body = {'roles': '🥮', 'profile_name': 0.0} res = requests.patch( f'{config.QA_BASE_URL}/profile/profile_id/{profile_id}/profile_type/{profile_type}', headers=grass_headers, json=patch_body, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == { 'profile_name': ['Not a valid string.'], 'roles': ['Not a valid list.'], }