Example #1
0
 def test_crash_bad_deliverytrack(self):
     from django.conf import settings
     release_form = ReleaseForm({'pk': self.delivery.release.pk, 'title_hidden': 'release_title',
                                 'artist_name_hidden': 'artist', 'label_name_hidden': 'label'})
     release_form.is_valid()
     # Modify the delivery in order to crash
     self.delivery.tracks[1].pk = 'aaa'
     release_processor = ReleaseProcessor(delivery=self.delivery, release_form=release_form, 
                                          artist=self.artist, label=self.label, disc=self.disc,
                                          vendor=self.vendor)
     # Test
     # No Album
     self.assertEqual(None, release_processor.build())
     self.assertFalse(self.artist.album_set.all())
     # No tracks
     for (index,track) in enumerate(self.delivery.tracks):
         if index != 1:
             self.assertRaises(Track.DoesNotExist, Track.objects.get, trackvendor__external_track_id=track.pk)
     # No imagefile
     self.assertEqual(0, ImageFile.objects.count())
     # No Files
     self.assertFalse(os.listdir(self.album_directory))
     # Error in the release_form
     self.assertFalse(release_form.report.success)
     self.assertTrue(release_form.report.error)
Example #2
0
 def test_remove(self):
     release_form = ReleaseForm({'pk': self.delivery.release.pk, 'remove': True})
     release_form.is_valid()
     release_processor = ReleaseProcessor(delivery=self.delivery, release_form=release_form, 
                                          artist=self.artist, label=self.label,
                                          disc=self.disc, vendor=self.vendor)
     release_processor.remove()
     self.assertFalse(os.listdir(self.album_directory))
Example #3
0
 def test_annuler(self):
     release_form = ReleaseForm(data={'pk': self.delivery.release.pk, 'annuler': True})
     release_form.is_valid()
     release_processor = ReleaseProcessor(delivery=self.delivery, release_form=release_form, 
                                          artist=self.artist, label=self.label,
                                          disc=self.disc, vendor=self.vendor)
     release_processor.remove()
     self.assertRaises(Album.DoesNotExist, Album.objects.get,
                       albumvendor__external_album_id=self.delivery.release.pk)
     self.assertFalse(os.path.exists(self.delivery.path))
     self.assertTrue(release_form.report.success)
Example #4
0
 def process(self):
     if self.artist_formset.is_valid() \
         and self.label_formset.is_valid() \
         and self.release_formset.is_valid():
         for form in self.release_formset.forms:
             delivery = self.batch.get_delivery(release_pk=form.cleaned_data['pk'])
             vendor = Vendor.objects.get(pk=delivery.vendor_id)
             artist = None # Pour pouvoir passer None au ReleaseProcessor dans le cas d'une compil
             # Process Artist
             if delivery.artist:
                 try:
                     # Artiste déjà connu
                     artist = Artist.objects.get(artistvendor__external_artist_id=delivery.artist.pk)
                 except Artist.DoesNotExist:
                     artist_form = self.artist_formset.get_by_pk(delivery.artist.pk)
                     if artist_form:
                         artist_processor = ArtistProcessor(delivery=delivery, artist_form=artist_form, 
                                                        vendor=vendor)
                         artist = artist_processor.build()
                     else:
                         # Si pas de formulaire et artiste inconnu -> compilation, c'est le release processor 
                         # qui créera l'artiste
                         pass
             # Process Label
             try:
                 label = Label.objects.get(labelvendor__external_label_id=delivery.label.pk)
             except Label.DoesNotExist:
                 label_form = self.label_formset.get_by_pk(delivery.label.pk)
                 delivery_label = delivery.label
                 label_processor = LabelProcessor(delivery=delivery, label_form=label_form, vendor=vendor)
                 label = label_processor.build()
             # Process Release                    
             if label:
                 disc = Disc.objects.get(status='default')
                 release_processor = ReleaseProcessor(delivery=delivery, release_form=form, artist=artist,
                                                      label=label, disc=disc, vendor=vendor)
                 album = release_processor.build()
Example #5
0
 def test_build_(self):
     release_form = ReleaseForm({'pk': self.delivery.release.pk})
     release_form.is_valid()
     release_processor = ReleaseProcessor(delivery=self.delivery, release_form=release_form, 
                                          label=self.label, disc=self.disc, vendor=self.vendor)
     produced_release = release_processor.build()
     expected_release = Album.objects.get(albumvendor__external_album_id=self.delivery.release.pk)
     # Test album
     self.assertEqual(expected_release, produced_release)
     produced_abumvendor = produced_release.albumvendor_set.get()
     # Test album_vendor
     self.assertEqual(self.delivery.release.pk, produced_abumvendor.external_album_id)
     self.assertEqual(self.vendor, produced_abumvendor.vendor)
     # Test artist
     produced_artist = produced_release.artist
     self.assertEqual(naming.COMPIL_FLAG, produced_artist.type)
     self.assertEqual("%s %s" % (produced_release.title, naming.COMPIL_POSTFIX), produced_artist.name)
     # No Files Left   
     self.assertFalse(os.path.exists(self.delivery_path))
     # Reports
     self._check_album_report(expected_release, release_form.report)
     self._check_artist_report(produced_artist, release_form.artist_report)
     expected_admin_artist_url = ADMIN_ARTIST_URL + str(produced_release.artist.pk)
     self.assertEqual(expected_admin_artist_url, release_form.report.admin_artist_url)
Example #6
0
 def test_build(self):
     release_form = ReleaseForm({'pk': self.delivery.release.pk})
     release_form.is_valid()
     release_processor = ReleaseProcessor(delivery=self.delivery, release_form=release_form, 
                                          artist=self.artist, label=self.label,
                                          disc=self.disc, vendor=self.vendor)
     produced_release = release_processor.build()
     expected_release = Album.objects.get(albumvendor__external_album_id=self.delivery.release.pk)
     self.assertEqual(expected_release, produced_release)
     # Test audiofiles
     produced_tracks = produced_release.track_set.all()
     produced_audiofiles = []
     for track in produced_tracks:
         produced_audiofiles.extend(list(track.audiofile_set.all())) 
     delivery_audiofiles = self.delivery.audiofiles()
     self.assertEqual(len(delivery_audiofiles), len(produced_audiofiles))
     for audiofile in produced_audiofiles:
         self.assertTrue(os.path.exists(audiofile.full_path()))
     # Test images
     self.check_album_images(produced_release, self.disc)
     # No Files Left   
     self.assertFalse(os.path.exists(self.delivery_path))
     # Reports
     self._check_album_report(expected_release, release_form.report)