def get_multiple_entities(entities): """Fetch multiple entities using their MBIDs. Args: entites: List of tuples containing the entity ID and the entity type. Returns: Dictionary containing the basic information related to the entities. { "id": uuid, "name/title": str, } Information related to the artists of release groups and the coordinates of the places is also included. """ entities_info = {} release_group_mbids = [ entity[0] for entity in filter( lambda entity: entity[1] == 'release_group', entities) ] artist_mbids = [ entity[0] for entity in filter(lambda entity: entity[1] == 'artist', entities) ] label_mbids = [ entity[0] for entity in filter(lambda entity: entity[1] == 'label', entities) ] place_mbids = [ entity[0] for entity in filter(lambda entity: entity[1] == 'place', entities) ] event_mbids = [ entity[0] for entity in filter(lambda entity: entity[1] == 'event', entities) ] work_mbids = [ entity[0] for entity in filter(lambda entity: entity[1] == 'work', entities) ] entities_info.update( fetch_multiple_release_groups( release_group_mbids, includes=['artists'], unknown_entities_for_missing=True, )) entities_info.update(fetch_multiple_artists(artist_mbids, )) entities_info.update(fetch_multiple_labels(label_mbids, )) entities_info.update( fetch_multiple_places( place_mbids, unknown_entities_for_missing=True, )) entities_info.update( fetch_multiple_events( event_mbids, unknown_entities_for_missing=True, )) entities_info.update(fetch_multiple_works(work_mbids, )) return entities_info
def test_fetch_multiple_places_empty(self, engine): places = mb_place.fetch_multiple_places( [ 'bea135c0-a32e-49be-85fd-9234c73fa0a8', 'bea135c0-3333-3333-3333-9234c73fa0a8' ], includes=['artist-rels', 'place-rels', 'url-rels']) assert list(places.keys()) == ['bea135c0-a32e-49be-85fd-9234c73fa0a8']
def test_fetch_multiple_places(self, engine): places = mb_place.fetch_multiple_places([ '4352063b-a833-421b-a420-e7fb295dece0', '2056ad56-cea9-4536-9f2d-58765a38829c' ]) assert places['4352063b-a833-421b-a420-e7fb295dece0'][ 'name'] == 'Royal Albert Hall' assert places['2056ad56-cea9-4536-9f2d-58765a38829c'][ 'name'] == 'Finnvox'
def test_fetch_multiple_places_redirect(self, engine): places = mb_place.fetch_multiple_places([ '4352063b-a833-421b-a420-e7fb295dece0', 'b1690ae6-5a37-46d7-99ae-b7e2d790485f' ]) assert len(places) == 2 assert places['b1690ae6-5a37-46d7-99ae-b7e2d790485f'][ 'mbid'] == 'bea135c0-a32e-49be-85fd-9234c73fa0a8' assert places['b1690ae6-5a37-46d7-99ae-b7e2d790485f'][ 'name'] == 'Berliner Philharmonie'
def test_fetch_multiple_places(self): self.place_query.return_value = [place_suisto, place_verkatehdas] places = mb_place.fetch_multiple_places([ 'f9587914-8505-4bd1-833b-16a3100a4948', 'd71ffe38-5eaf-426b-9a2e-e1f21bc84609' ]) self.assertEqual( places['d71ffe38-5eaf-426b-9a2e-e1f21bc84609']['name'], 'Suisto') self.assertEqual( places['f9587914-8505-4bd1-833b-16a3100a4948']['name'], 'Verkatehdas')
def test_fetch_multiple_places_empty(self): self.place_query.return_value = [] places = mb_place.fetch_multiple_places( [ 'f9587914-8505-4bd1-833b-16a3100a4948', 'd71ffe38-5eaf-426b-9a2e-e1f21bc84609' ], includes=['artist-rels', 'place-rels', 'url-rels'], unknown_entities_for_missing=True) self.assertEqual( places['d71ffe38-5eaf-426b-9a2e-e1f21bc84609']['name'], unknown_place.name) self.assertEqual( places['f9587914-8505-4bd1-833b-16a3100a4948']['name'], unknown_place.name)
def get_place_by_id(mbid): """Get place with the MusicBrainz ID. Args: mbid (uuid): MBID(gid) of the place. Returns: Dictionary containing the place information. """ key = cache.gen_key('place', mbid) place = cache.get(key) if not place: place = db.fetch_multiple_places( [mbid], includes=[ 'artist-rels', 'place-rels', 'release-group-rels', 'url-rels' ], ).get(mbid) cache.set(key=key, val=place, time=DEFAULT_CACHE_EXPIRATION) return place_rel.process(place)