def test_attribute_ids_lookup_by_tag_values(self): """Test that IDs are looked up in the ID cache based on values from the tag being inserted. """ ruiner = uuid.UUID('350c49d9-fa38-585a-a0d9-7343c8b910ed') a_wilhelm_scream = uuid.UUID('aa143f55-65e3-59f3-a1d8-36eac7024e86') hardcore = uuid.UUID('54cde78b-6d4b-5634-a666-cb7fa674c73f') tag = MockTag() tag.path = '/home/something/music/song.flac' tag.album = 'Ruiner' tag.artist = 'A Wilhelm Scream' tag.genre = 'Hardcore' tag.length = 150 tag.title = 'The Soft Sell' tag.track = 4 tag.year = 2005 cache = mock.Mock(spec=avalon.cache.IdLookupCache) cache.get_album_id.return_value = ruiner cache.get_artist_id.return_value = a_wilhelm_scream cache.get_genre_id('Hardcore').return_value = hardcore session = mock.Mock(spec=DummySession) id_gen = mock.Mock() model_cls = mock.Mock() model = mock.Mock(spec=avalon.models.Track) model_cls.return_value = model id_gen.return_value = uuid.UUID('450b3e88-01e0-537a-80cd-c8692c903c76') inserter = avalon.tags.insert.TrackLoader(session, [tag], cache) inserter.insert(model_cls, id_gen) session.add_all.assert_called_once_with([model])
def test_get_genre_id_case_insensitive(self): """Test that we can translate an genre name to ID in a case insensitive fashion""" model1 = avalon.models.Genre() model1.id = uuid.UUID("8794d7b7-fff3-50bb-b1f1-438659e05fe5") model1.name = 'Punk' dao = mock.Mock(spec=avalon.models.ReadOnlyDao) dao.get_all_albums.return_value = [] dao.get_all_artists.return_value = [] dao.get_all_genres.return_value = [model1] cache = avalon.cache.IdLookupCache(dao).reload() assert uuid.UUID("8794d7b7-fff3-50bb-b1f1-438659e05fe5") == \ cache.get_genre_id('PUNK')