"""Test ArtistResourceSchema.""" import pytest from marshmallow import ValidationError from permissions.constants import constants from permissions.validations.schemas.artist_resource import ArtistResourceSchema @pytest.mark.parametrize( ('schema', 'expected_err'), [ # required fields missing [{}, {'artist_id': ['Missing data for required field.']}], # validation errors [ {'resource_type': 'LabelParticipant', 'artist_id': 'foo'}, { 'artist_id': ['Not a valid integer.'], }, ], [ {'resource_type': 'Foo', 'artist_id': 123}, { 'resource_type': [ f"Must be one of: {', '.join(constants.TYPES_ASSOCIATED_WITH_LABEL)}." ] }, ], ], ) def test_load_validate_errors(schema, expected_err): """Test load and validate for ArtistResourceSchema.""" try: ArtistResourceSchema().load(schema) assert not expected_err except ValidationError as err: assert err.messages == expected_err @pytest.mark.parametrize( 'schema', [ {'resource_type': 'LabelParticipant', 'artist_id': 123}, {'resource_type': 'SubAccount', 'artist_id': 123}, ], ) def test_pre_load(schema): """Test pre_load for ArtistResourceSchema.""" actual = ArtistResourceSchema().load(schema) assert actual == schema