"""Functional tests for POST full-artists/bulk handler.""" import json from tests.testutils import db @db.test_schema def test_full_artists_bulk(client): """Test endpoint without additional params.""" artists = [ { 'artist_id': 1, 'name': 'One', 'vendor_id': 1234, 'last_updated': '2000-01-01' }, { 'artist_id': 2, 'name': 'Two', 'vendor_id': 1234, 'last_updated': '2000-01-01' }, { 'artist_id': 3, 'name': 'Three', 'vendor_id': 456, 'last_updated': '2000-01-01' }, { 'artist_id': 4, 'name': 'Four', 'vendor_id': 1234, 'last_updated': '2000-01-01' } ] releases = [ { 'release_id': 1, 'artist_id': 1, 'genre_id': 1, 'last_updated': '2000-01-01' }, { 'release_id': 2, 'artist_id': 1, 'genre_id': 2, 'last_updated': '2000-01-01' }, { 'release_id': 3, 'artist_id': 2, 'genre_id': 1, 'last_updated': '2000-01-01' } ] genres = [ {'genre_id': 1, 'genre': 'Rock'}, {'genre_id': 2, 'genre': 'Punk'} ] for artist in artists: db.seed_artist(artist) for release in releases: db.seed_release(release) for genre in genres: db.seed_genre(genre) account_type = 'vendor' account_id = '1234' data = {'artist_ids': [1, 2]} res = client.post( '/{0}/{1}/full-artists/bulk'.format(account_type, account_id), data=json.dumps(data)) res_json = json.loads(res.data.decode('utf-8')) assert len(res_json['items']) == 2 assert { 'artist_id': 1, 'name': 'One', 'genres': ['Rock', 'Punk'] } in res_json['items'] assert { 'artist_id': 2, 'name': 'Two', 'genres': ['Rock'] } in res_json['items'] def test_full_artists_missing_params(client): """Test endpoint when called without artist_ids.""" account_type = 'vendor' account_id = '1234' data = {'artist_ids': []} res = client.post( '/{0}/{1}/full-artists/bulk'.format(account_type, account_id), data=json.dumps(data)) assert res.status_code == 400