"""Tests for the POST /profile/identity/ endpoint.""" import time import uuid import requests from tests.integration import config, constants def test_create_and_fetch_profile(new_identity, grass_headers): """Test creating a profile (with a profile id in payload) and fetching it.""" identity_id = new_identity['id'] profile_id = int(time.time()) profile_type = 'InsightsProfile' profile_payload = { 'profile_id': profile_id, 'profile_name': 'Test InsightsProfile crud', 'profile_type': profile_type, 'roles': ['catalog'], } res = requests.post( f'{config.QA_BASE_URL}/profile/identity/{identity_id}', headers=grass_headers, json=profile_payload, ) assert res.status_code == 201 body = res.json() for key, value in profile_payload.items(): assert body[key] == value # Now fetch it! 🎾 res = requests.get( f'{config.QA_BASE_URL}/profile/profile_id/{profile_id}/profile_type/{profile_type}', headers=grass_headers, ) body = res.json() for key, value in profile_payload.items(): assert body[key] == value assert body['uuid'] def test_create_profile_without_profile_id_in_payload(new_identity, grass_headers): """Test creating a profile without a profile id in the payload.""" identity_id = new_identity['id'] profile_type = 'InsightsProfile' profile_payload = { 'profile_name': 'Test InsightsProfile crud', 'profile_type': profile_type, 'roles': ['catalog'], } res = requests.post( f'{config.QA_BASE_URL}/profile/identity/{identity_id}', headers=grass_headers, json=profile_payload, ) assert res.status_code == 201 body = res.json() for key, value in profile_payload.items(): assert body[key] == value assert body['profile_id'] def test_create_profile_with_nonexistent_identity_id(grass_headers): """Test attempting to create a profile with a nonexistent identity id.""" profile_payload = { 'profile_name': 'Test InsightsProfile crud', 'profile_type': 'InsightsProfile', 'roles': ['catalog'], } res = requests.post( f'{config.QA_BASE_URL}/profile/identity/{uuid.uuid4()}', headers=grass_headers, json=profile_payload, ) assert res.status_code == 404 body = res.json() assert body['code'] == 'not_found_error' assert body['message'] == 'Identity not found' def test_create_profile_with_invalid_body(grass_headers): """Test attempting to create a profile with an invalid body.""" profile_payload = {'profile_name': -1, 'profile_type': '🍉', 'roles': '🥥'} res = requests.post( f'{config.QA_BASE_URL}/profile/identity/{constants.SETTINGS_ONLY_USER_IDENTITY_ID}', headers=grass_headers, json=profile_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == { 'profile_name': ['Not a valid string.'], 'profile_type': ['Invalid enum member 🍉'], 'roles': ['Not a valid list.'], }