"""Test edit_profile_resources.py.""" import pytest from marshmallow import ValidationError from permissions.constants import constants from permissions.validations.schemas.edit_profile_resources import EditProfileResourcesSchema @pytest.mark.parametrize( ('schema', 'expected_err'), [ # valid data [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], [ { 'identity_id': 'uuid', 'resource_access': [ { 'resource_type': 'Vendor', 'roles': ['accounting', 'analytics'], 'uuid': '7123', }, {'resource_type': 'Subaccount', 'roles': ['catalog'], 'uuid': '8869'}, {'resource_type': 'LabelParticipant', 'roles': ['analytics'], 'uuid': '8869'}, ], }, False, ], [ { 'identity_id': 'uuid', 'overwrite_existing_access': False, 'resource_access': [ {'resource_type': 'Vendor', 'roles': ['analytics'], 'uuid': '7123'} ], }, False, ], # invalid data [ { 'resource_access': [ { 'resource_type': 'Vendor', 'roles': ['accounting', 'analytics'], 'uuid': '7123', }, {'resource_type': 'Subaccount', 'roles': ['catalog'], 'uuid': '8869'}, {'resource_type': 'LabelParticipant', 'roles': ['analytics'], 'uuid': '8869'}, ], }, {'identity_id': ['Missing data for required field.']}, ], [ { 'identity_id': 'uuid', 'resource_access': [], }, {'resource_access': ['Shorter than minimum length 1.']}, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Foo', 'roles': ['accounting', 'analytics'], 'uuid': '7123'}, {'resource_type': 'Subaccount', 'roles': ['catalog'], 'uuid': '8869'}, {'resource_type': 'LabelParticipant', 'roles': ['analytics'], 'uuid': '8869'}, ], }, { 'resource_access': { 0: { 'resource_type': [ f"Must be one of: {', '.join(constants.SETTINGS_SUPPORT_MAPPING['resourceTypes'])}." ] } } }, ], [ { 'identity_id': 'uuid', 'resource_access': [ {'resource_type': 'Vendor', 'roles': [], 'uuid': '7123'}, {'resource_type': 'Subaccount', 'roles': ['catalog'], 'uuid': '8869'}, {'resource_type': 'LabelParticipant', 'roles': ['analytics'], 'uuid': '8869'}, ], }, {'resource_access': {0: {'roles': ['Shorter than minimum length 1.']}}}, ], ], ) def test_pre_load(schema, expected_err): """Test pre_load for EditProfileResourcesSchema.""" try: EditProfileResourcesSchema().load(schema) assert not expected_err except ValidationError as err: assert err.messages == expected_err