"""Tests for the GET /users/identity/ endpoint.""" import uuid import pytest import requests from tests.integration import config, conftest, constants _REQUESTER = 'Orchard-Requestor-Service' _REQUESTER_SERVICE = 'ows-grass' def test_get_nonexistent_identity(grass_headers) -> None: """Test getting an identity that doesn't exist returns 404.""" res = requests.get( f'{config.QA_BASE_URL}/users/identity/{uuid.uuid4()}', headers=grass_headers, ) assert res.status_code == 404 body = res.json() assert body['code'] == 'not_found_error' assert body['message'] == 'Identity not found' @pytest.mark.parametrize( ('identity_id', 'expected_status'), [ pytest.param(constants.INTEGRATION_TEST_USER_IDENTITY_ID, 200, id='regular identity'), pytest.param( constants.EMPLOYEE_NOT_SETTINGS_ADMIN_IDENTITY_ID, 200, id='employee identity, not settings admin', ), pytest.param( constants.EMPLOYEE_SETTINGS_ADMIN_IDENTITY_ID, 404, id='employee identity, settings admin', ), ], ) def test_get_identity_settings_profile_not_super_admin( grass_headers, identity_id, expected_status ) -> None: """Settings profile with requester service: loads regular and non-admin employees. Blocks settings admin employees. """ headers = {**grass_headers, _REQUESTER: _REQUESTER_SERVICE} res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=headers, ) assert res.status_code == expected_status @pytest.mark.parametrize( 'identity_id', [ pytest.param(constants.INTEGRATION_TEST_USER_IDENTITY_ID, id='regular identity'), pytest.param( constants.EMPLOYEE_NOT_SETTINGS_ADMIN_IDENTITY_ID, id='employee identity, not settings admin', ), pytest.param( constants.EMPLOYEE_SETTINGS_ADMIN_IDENTITY_ID, id='employee identity, settings admin', ), ], ) def test_get_identity_settings_profile_is_super_admin( settings_admin_with_ff_grass_headers, identity_id ) -> None: """Test Settings super admin can load employee identities.""" headers = {**settings_admin_with_ff_grass_headers, _REQUESTER: _REQUESTER_SERVICE} res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=headers, ) assert res.status_code == 200 assert res.json()['id'] == identity_id @pytest.mark.parametrize( 'identity_id', [ pytest.param(constants.INTEGRATION_TEST_USER_IDENTITY_ID, id='regular identity'), pytest.param(constants.EMPLOYEE_SETTINGS_ADMIN_IDENTITY_ID, id='employee identity'), ], ) def test_get_identity_label_profile(grass_headers, identity_id) -> None: """Test LabelProfile with requester service can load both regular and employee identities.""" headers = { **conftest.create_grass_headers( identity_id=grass_headers['Orchard-Identity-Id'], identity_uuid=grass_headers['Orchard-Identity-Id'], profile_type='LabelProfile', profile_id='60836', ), _REQUESTER: _REQUESTER_SERVICE, } res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=headers, ) assert res.status_code == 200 assert res.json()['id'] == identity_id @pytest.mark.parametrize( 'identity_id', [ pytest.param(constants.EMPLOYEE_SETTINGS_ADMIN_IDENTITY_ID, id='employee identity'), pytest.param(constants.INTEGRATION_TEST_USER_IDENTITY_ID, id='regular identity'), ], ) def test_get_identity_seat_admin(seat_admin_jwt, identity_id) -> None: """Test seat admin JWT can load both employee and regular identities.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.get( f'{config.QA_BASE_URL}/users/identity/{identity_id}', headers=headers, ) assert res.status_code == 200 assert res.json()['id'] == identity_id