"""Test get_profiles_for_admin endpoint.""" import json from unittest.mock import patch import pytest from owsresponse import response from pythonfeatures import pythonfeatures from permissions import handlers # noqa (handlers are imported for test client) from permissions.constants import constants, error @pytest.mark.parametrize( ('url', 'expected'), [ [ '/identity/admin/profiles?label_participant=123&label_participant=456', response.Response( message={ 'items': {'foo': 'bar'}, 'pagination': { 'type': 'standard', 'total_records': 1, 'limit': 50, 'offset': 0, }, } ), ], [ '/identity/admin/profiles?profile_type=FooProfile&profile_type=InsightsProfile&active=sure', # noqa response.create_error_response( code=error.ERROR_CODE_VALIDATION_ERROR, message={ 'active': {'0': ['Must be one of: Y, N.']}, 'profile_type': { '0': [ f"Must be one of: {', '.join(constants.SETTINGS_SUPPORT_MAPPING['profileTypes'])}." # noqa ] }, }, ), ], [ '/identity/admin/profiles?profile_type=Insights&label_participant=456', response.create_error_response( code=error.ERROR_CODE_VALIDATION_ERROR, message={ 'profile_type': { '0': [ f"Must be one of: {', '.join(constants.SETTINGS_SUPPORT_MAPPING['profileTypes'])}." # noqa ] } }, ), ], ], ) @patch('permissions.handlers.handlers.g') def test_get_profiles_for_admin_schema_validation( mock_g, app_context, mocker, fixture_client, url, expected ): """Verify get_profiles_for_admin for schema validation errors.""" mock_g.request_context.context_type = 'profile' mock_g.request_context.profile_type = 'InsightsProfile' mocker.patch( 'permissions.logic.resource.get_user_profiles_for_admin', return_value=response.Response(message={'data': {'foo': 'bar'}, 'total': 1}), ) mocker.patch.object( pythonfeatures, 'get_single_feature', return_value=response.Response(message='enabled') ) handler_response = fixture_client.get( url, json={}, headers={'Content-Type': 'application/json'} ) result = json.loads(handler_response.data.decode()) assert handler_response.status_code == expected.status if expected.status == 200: assert result == expected.message else: assert result == expected.errors