"""Tests for the POST /users/identity endpoint.""" import requests from tests.integration import config def test_create_and_fetch_identity(new_identity): """Test creating an identity and fetching it.""" identity_id = new_identity['id'] res = requests.get(f'{config.QA_BASE_URL}/users/identity/{identity_id}') assert res.status_code == 200 body = res.json() # Not == created_identity because this response has an extra lil field for key, value in new_identity.items(): assert body[key] == value def test_create_identity_missing_field(grass_headers, identity_payload): """Test attempting to create an identity with a partial payload.""" del identity_payload['email'] res = requests.post( f'{config.QA_BASE_URL}/users/identity', headers=grass_headers, json=identity_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == {'email': ['Missing data for required field.']} def test_create_identity_invalid_field(grass_headers, identity_payload): """Test attempting to create an identity with an invalid body.""" identity_payload['identity_id'] = 'too-short-id' res = requests.post( f'{config.QA_BASE_URL}/users/identity', headers=grass_headers, json=identity_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == {'identity_id': ['Length must be between 22 and 36.']} def test_create_identity_already_exists(grass_headers, identity_payload, new_identity): """Test attempting to create an identity when it already exists.""" res = requests.post( f'{config.QA_BASE_URL}/users/identity', headers=grass_headers, json=identity_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'already_exists' assert body['message'] == 'Identity already exists.'