"""Functional tests for GET full-artists handler.""" import json from tests.testutils import db @db.test_schema def test_artist_document(client): """Test artist cloudsearch document endpoint.""" artists = [ { 'artist_id': 1, 'name': 'One', 'vendor_id': 1234, 'last_updated': '2020-01-01' } ] releases = [ { 'release_id': 1, 'artist_id': 1, 'last_updated': '2020-01-01' }, { 'release_id': 2, 'artist_id': 1, 'last_updated': '2020-01-01' } ] for artist in artists: db.seed_artist(artist) for release in releases: db.seed_release(release) artist_id = 1 res = client.get('/artist/{0}/document'.format(artist_id)) res_json = json.loads(res.data.decode('utf-8')) assert len(res_json) == 4 assert { 'artist_id': 1, 'artist_name': 'One', 'subaccount_id': [], 'vendor_id': 1234 } in [res_json] @db.test_schema def test_artist_document_subaccount(client): """Test artist cloudsearch document endpoint with subaccounts list.""" artists = [ { 'artist_id': 2, 'name': 'One', 'vendor_id': 1234, 'last_updated': '2020-01-01' } ] releases = [ { 'release_id': 1, 'artist_id': 2, 'subaccount_id': 1, 'last_updated': '2020-01-01' }, { 'release_id': 2, 'artist_id': 2, 'subaccount_id': 2, 'last_updated': '2020-01-01' } ] for artist in artists: db.seed_artist(artist) for release in releases: db.seed_release(release) artist_id = 2 res = client.get('/artist/{0}/document'.format(artist_id)) res_json = json.loads(res.data.decode('utf-8')) assert res.status_code == 200 assert len(res_json) == 4 assert { 'artist_id': 2, 'artist_name': 'One', 'vendor_id': 1234, 'subaccount_id': ['1', '2'] } in [res_json] @db.test_schema def test_get_artist_document_not_found(client): """Test artist cloudsearch document endpoint with not found response.""" artists = [ { 'artist_id': 3, 'name': 'One', 'vendor_id': 1234, 'last_updated': '2020-01-01' } ] releases = [ { 'release_id': 1, 'artist_id': 3, 'last_updated': '2020-01-01' } ] for artist in artists: db.seed_artist(artist) for release in releases: db.seed_release(release) artist_id = 4 res = client.get('/artist/{0}/document'.format(artist_id)) res_json = json.loads(res.data.decode('utf-8')) assert res.status_code == 404 assert res_json['message'] == 'No artist exists for ID {}'.\ format(artist_id) assert res_json['code'] == 'not_found_error'