"""Tests for the PATCH /users/identity/ endpoint.""" import uuid import requests from tests.integration import config def test_create_update_and_fetch(grass_headers, new_identity): """Test creating and updating an identity, then fetching the updated identity.""" identity_id = new_identity['id'] new_name = 'UPDATED! ows-users identity integration test' updated_identity = {**new_identity, 'name': new_name} updated_identity.pop('id') updated_identity.pop('is_employee') res = requests.patch( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=grass_headers, json=updated_identity, ) assert res.status_code == 200, res.text body = res.json() for key, value in updated_identity.items(): assert body[key] == value # And fetch again! 🐶 res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=grass_headers, ) assert res.status_code == 200, res.text body = res.json() for key, value in updated_identity.items(): assert body[key] == value def test_update_nonexistent_identity(grass_headers, identity_payload): """Test updating a nonexistent identity.""" res = requests.patch( f'{config.QA_BASE_URL}/users/identity/{uuid.uuid4()}', headers=grass_headers, json=identity_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'not_found' assert body['message'] == 'Identity not found' def test_update_identity_with_invalid_payload(grass_headers, identity_payload): """Test updating an existing identity with an invalid payload.""" identity_payload['email'] = -1 identity_payload['name'] = 0.0 res = requests.patch( f'{config.QA_BASE_URL}/users/identity/{uuid.uuid4()}', headers=grass_headers, json=identity_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == { 'email': ['Not a valid email address.'], 'name': ['Not a valid string.'], }