"""Releases Model Tests. Testing the persistence of the releases model """ from artist.models.releases import get_artists from tests.testutils import db @db.test_schema def test_get_artists( artist_infos, release_artists, release_id, track_artists, track_writers, tracks ): """Test the get_artists method.""" models = artist_infos models += release_artists models += tracks models += track_artists models += track_writers db.seed_models(models) result = get_artists(release_id) assert result.message == { 'release_artists': [ { 'id': 1, 'name': 'First artist', 'role': 'First role' }, { 'id': 2, 'name': 'Second artist', 'role': 'Second role' } ], 'track_artists': [ { 'id': 1, 'name': 'First track artist', 'role': 'First track role', 'track_id': 1 }, { 'id': 2, 'name': 'First track artist', 'role': 'First track role', 'track_id': 2 }, { 'id': 3, 'name': 'First track artist', 'role': 'First track role', 'track_id': 3 }, { 'id': 4, 'name': 'First track artist', 'role': 'First track role', 'track_id': 4 }, { 'id': 5, 'name': 'First track artist', 'role': 'First track role', 'track_id': 5 } ], 'track_writers': [ { 'id': 1, 'name': 'First track writer', 'track_id': 1 }, { 'id': 2, 'name': 'First track writer', 'track_id': 2 }, { 'id': 3, 'name': 'First track writer', 'track_id': 3 }, { 'id': 4, 'name': 'First track writer', 'track_id': 4 }, { 'id': 5, 'name': 'First track writer', 'track_id': 5 } ] } @db.test_schema def test_get_artists_with_isni_ids( artist_infos_with_isnis, release_artists, release_id, track_artists, track_writers, tracks ): """Test the get_artists method.""" models = artist_infos_with_isnis models += release_artists models += tracks models += track_artists models += track_writers db.seed_models(models) result = get_artists(release_id) assert result.message == { 'release_artists': [ { 'id': 1, 'name': 'First artist', 'role': 'First role' }, { 'id': 2, 'name': 'Second artist', 'role': 'Second role' } ], 'track_artists': [ { 'id': 1, 'name': 'First track artist', 'role': 'First track role', 'track_id': 1 }, { 'id': 2, 'name': 'First track artist', 'role': 'First track role', 'track_id': 2 }, { 'id': 3, 'name': 'First track artist', 'role': 'First track role', 'track_id': 3 }, { 'id': 4, 'name': 'First track artist', 'role': 'First track role', 'track_id': 4 }, { 'id': 5, 'name': 'First track artist', 'role': 'First track role', 'track_id': 5 } ], 'track_writers': [ { 'id': 1, 'name': 'First track writer', 'track_id': 1 }, { 'id': 2, 'name': 'First track writer', 'track_id': 2 }, { 'id': 3, 'name': 'First track writer', 'track_id': 3 }, { 'id': 4, 'name': 'First track writer', 'track_id': 4 }, { 'id': 5, 'name': 'First track writer', 'track_id': 5 } ] } @db.test_schema def test_get_artists_no_identifiers( artist_infos, release_artists, release_id, track_artists, track_writers, tracks ): """Test get_artist method if artists have no identifiers.""" models = artist_infos models += release_artists models += tracks models += track_artists models += track_writers db.seed_models(models) result = get_artists(release_id) assert result.message == { 'release_artists': [ { 'id': 1, 'name': 'First artist', 'role': 'First role' }, { 'id': 2, 'name': 'Second artist', 'role': 'Second role' } ], 'track_artists': [ { 'id': 1, 'name': 'First track artist', 'role': 'First track role', 'track_id': 1 }, { 'id': 2, 'name': 'First track artist', 'role': 'First track role', 'track_id': 2 }, { 'id': 3, 'name': 'First track artist', 'role': 'First track role', 'track_id': 3 }, { 'id': 4, 'name': 'First track artist', 'role': 'First track role', 'track_id': 4 }, { 'id': 5, 'name': 'First track artist', 'role': 'First track role', 'track_id': 5 } ], 'track_writers': [ { 'id': 1, 'name': 'First track writer', 'track_id': 1 }, { 'id': 2, 'name': 'First track writer', 'track_id': 2 }, { 'id': 3, 'name': 'First track writer', 'track_id': 3 }, { 'id': 4, 'name': 'First track writer', 'track_id': 4 }, { 'id': 5, 'name': 'First track writer', 'track_id': 5 } ] } @db.test_schema def test_get_artists_with_isnis_and_no_identifiers( artist_infos_with_isnis, release_artists, release_id, track_artists, track_writers, tracks ): """Test get_artist method if artists have no identifiers.""" models = artist_infos_with_isnis models += release_artists models += tracks models += track_artists models += track_writers db.seed_models(models) result = get_artists(release_id) assert result.message == { 'release_artists': [ { 'id': 1, 'name': 'First artist', 'role': 'First role' }, { 'id': 2, 'name': 'Second artist', 'role': 'Second role' } ], 'track_artists': [ { 'id': 1, 'name': 'First track artist', 'role': 'First track role', 'track_id': 1 }, { 'id': 2, 'name': 'First track artist', 'role': 'First track role', 'track_id': 2 }, { 'id': 3, 'name': 'First track artist', 'role': 'First track role', 'track_id': 3 }, { 'id': 4, 'name': 'First track artist', 'role': 'First track role', 'track_id': 4 }, { 'id': 5, 'name': 'First track artist', 'role': 'First track role', 'track_id': 5 } ], 'track_writers': [ { 'id': 1, 'name': 'First track writer', 'track_id': 1 }, { 'id': 2, 'name': 'First track writer', 'track_id': 2 }, { 'id': 3, 'name': 'First track writer', 'track_id': 3 }, { 'id': 4, 'name': 'First track writer', 'track_id': 4 }, { 'id': 5, 'name': 'First track writer', 'track_id': 5 } ] } @db.test_schema def test_get_artists_no_artists(release_id): """Test get_artist function if there are no artists.""" result = get_artists(release_id) assert result.message == { 'release_artists': [], 'track_artists': [], 'track_writers': [] }