def test_composers(self): self.composer1id = str(uuid.uuid4()) self.composer2id = str(uuid.uuid4()) self.composer3id = str(uuid.uuid4()) self.composer4id = str(uuid.uuid4()) self.composer1 = models.Composer.objects.create(name="composer1", mbid=self.composer1id) self.composer2 = models.Composer.objects.create(name="composer2", mbid=self.composer2id) self.composer3 = models.Composer.objects.create(name="composer3", mbid=self.composer3id) self.composer4 = models.Composer.objects.create(name="composer4", mbid=self.composer4id) self.work1.composers.add(self.composer1) self.work2.composers.add(self.composer1) self.work2.composers.add(self.composer2) self.work2.lyricists.add(self.composer3) self.work1.lyricists.add(self.composer4) ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() with self.assertRaises(models.Composer.DoesNotExist): models.Composer.objects.get(mbid=self.composer2id) with self.assertRaises(models.Composer.DoesNotExist): models.Composer.objects.get(mbid=self.composer3id) self.assertIsNotNone( models.Composer.objects.get(mbid=self.composer1id)) self.assertIsNotNone( models.Composer.objects.get(mbid=self.composer4id))
def test_performance_artists(self): # If an artist performs on a track on a deleted album # and a non-deleted album, don't remove it self.artist3id = str(uuid.uuid4()) self.artist4id = str(uuid.uuid4()) self.artist3 = models.Artist.objects.create(name="artist3", mbid=self.artist3id) self.artist4 = models.Artist.objects.create(name="artist4", mbid=self.artist4id) inst = models.Instrument.objects.create(name="an instrument") models.InstrumentPerformance.objects.create(instrument=inst, artist=self.artist3, recording=self.recording1) models.InstrumentPerformance.objects.create(instrument=inst, artist=self.artist3, recording=self.recording2) models.InstrumentPerformance.objects.create(instrument=inst, artist=self.artist4, recording=self.recording2) models.InstrumentPerformance.objects.create(instrument=inst, artist=self.artist4, recording=self.recording3) ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() with self.assertRaises(models.Artist.DoesNotExist): models.Artist.objects.get(mbid=self.artist4id) self.assertIsNotNone(models.Artist.objects.get(mbid=self.artist3id))
def test_shared_recording(self): # If recording 1 is part of concert 1 and 2, and # recording 2 is part of concert 3 you delete concert 2 and 3 # then recording 1 stays and recording 2 gets deleted ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() with self.assertRaises(models.Recording.DoesNotExist): models.Recording.objects.get(mbid=self.recording2id) self.assertIsNotNone( models.Recording.objects.get(mbid=self.recording1.mbid))
def test_dont_remove_dummy_artist(self): # some artists are flagged as 'dummy' - that is, not imported # by the script. We shouldn't remove them dummyid = str(uuid.uuid4()) a = models.Artist.objects.create(name="dummyartist", mbid=dummyid, dummy=True) ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() self.assertIsNotNone(models.Artist.objects.get(mbid=dummyid))
def get_release_importer(collection): name = collection.name.lower() name = name.lower() data_coll = data.models.Collection.objects.get(collectionid=collection.id) ri = None if "hindustani" in name: ri = hindustani_importer.HindustaniReleaseImporter(data_coll) elif "carnatic" in name: ri = carnatic_importer.CarnaticReleaseImporter(data_coll) elif "makam" in name: ri = makam_importer.MakamReleaseImporter(data_coll) elif "andalusian" in name: ri = andalusian_importer.AndalusianReleaseImporter(data_coll) return ri
def test_shared_work(self): # If a work is part of a non-deleted recording and a deleted one, # don't delete the work ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() with self.assertRaises(models.Recording.DoesNotExist): models.Recording.objects.get(mbid=self.recording3id) with self.assertRaises(models.Work.DoesNotExist): models.Work.objects.get(mbid=self.work2id) self.assertIsNotNone( models.Recording.objects.get(mbid=self.recording1id)) self.assertIsNotNone(models.Work.objects.get(mbid=self.work1id))
def test_remove_concert_with_shared_artist(self): # If you remove concert 2 and 3 then artist 1 should still be here # but artist 2 should be deleted ri = carnatic_importer.CarnaticReleaseImporter(self.coll1) ri.imported_releases.append(self.concert1id) ri.remove_nonimported_items() with self.assertRaises(models.Concert.DoesNotExist): models.Concert.objects.get(mbid=self.concert2id) with self.assertRaises(models.Concert.DoesNotExist): models.Concert.objects.get(mbid=self.concert3id) with self.assertRaises(models.Artist.DoesNotExist): models.Artist.objects.get(mbid=self.artist2id) self.assertIsNotNone(models.Artist.objects.get(mbid=self.artist1id)) self.assertIsNotNone(models.Concert.objects.get(mbid=self.concert1id))