"""Test add_resource_to_profile endpoint.""" import json from unittest.mock import patch import pytest from owsresponse import response from permissions import handlers # noqa (handlers are imported for test client) from permissions.constants import constants, error @pytest.mark.parametrize( ('url', 'expected'), [ [ '/identity/user-uuid-123/direct-access/resources/LabelParticipant?limit=10&offset=2', response.Response( message={ 'items': {'foo': 'bar'}, 'pagination': { 'type': 'standard', 'total_records': 1, 'limit': 10, 'offset': 2, 'active': True, }, } ), ], [ '/identity/user-uuid-123/direct-access/resources/ArtistInfo?limit=foo', # noqa response.create_error_response( code=error.ERROR_CODE_VALIDATION_ERROR, message={ 'limit': {'0': ['Not a valid integer.']}, 'resource_type': [ f"Must be one of: {', '.join(constants.SETTINGS_SUPPORT_MAPPING['resourceTypes'])}." # noqa ], }, ), ], ], ) @patch('permissions.handlers.handlers.g') def test_user_resources_for_admin_schema_validation( mock_g, mocker, app_context, fixture_client, url, expected ): """Verify get_user_resources_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_resources_for_admin', return_value=response.Response(message={'data': {'foo': 'bar'}, 'total': 1}), ) 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