"""Test POST /users/identity//device endpoint.""" import uuid import requests from tests.integration import config def test_create_and_fetch_device(new_identity, device_payload, grass_headers): """Test creating and then fetching a user device.""" identity_id = new_identity['id'] res = requests.post( f'{config.QA_BASE_URL}/users/identity/{identity_id}/device', headers=grass_headers, json=device_payload, ) assert res.status_code == 200 body = res.json() for key, value in device_payload.items(): assert body[key] == value assert body['endpoint_arn'] # Now fetch the newly created device 🐕 res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}/device', headers=grass_headers, ) assert res.status_code == 200 body = res.json() assert len(body) == 1 device = body[0] for key, value in device_payload.items(): assert device[key] == value assert device['endpoint_arn'] def test_create_device_with_invalid_platform_type(new_identity, device_payload, grass_headers): """Test attempting to create a user device with an invalid platform type.""" device_payload['platform_type'] = 'windows' identity_id = new_identity['id'] res = requests.post( f'{config.QA_BASE_URL}/users/identity/{identity_id}/device', headers=grass_headers, json=device_payload, ) assert res.status_code == 400 body = res.json() assert body['code'] == 'validation_error' assert body['message'] == {'platform_type': ['Invalid enum member windows']} def test_create_device_for_nonexistent_identity(device_payload, grass_headers): """Test attempting to create a user device for a nonexistent identity.""" identity_id = uuid.uuid4() res = requests.post( f'{config.QA_BASE_URL}/users/identity/{identity_id}/device', headers=grass_headers, json=device_payload, ) assert res.status_code == 404 body = res.json() assert body['code'] == 'not_found_error' assert body['message'] == 'Identity not found'