def test_filename_remove_non_ascii(self): artist = Artist.objects.create(name=u'téta tata') album = Album.objects.create(title=u'tutu tutu', artist=artist) track = Track.objects.create(title=u'my track', album=album) path = "/albums/%s/mp3/teta_tata__my_track.mp3" % (album.pk,) audiofile_mapper = AudioFileMapper(delivery_audiofile=self.delivery_audiofile, track=track, disc=self.disc) produced_audiofile = audiofile_mapper.create() self.assertEqual(path, produced_audiofile.path)
def test_cut_audiofilename_when_too_long(self): artist = Artist.objects.create(name='aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd') album = Album.objects.create(title=u'téta tata', artist=artist) track = Track.objects.create(title='aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd', album=album) path = "/albums/%s/mp3/aaaaaaaaaabbbbbbbbbbcccccccccc__aaaaaaaaaabbbbbbbbbbcccccccccc.mp3" % (album.pk,) audiofile_mapper = AudioFileMapper(delivery_audiofile=self.delivery_audiofile, track=track, disc=self.disc) produced_audiofile = audiofile_mapper.create() self.assertEqual(path, produced_audiofile.path)
def test_main(self): artist = Artist.objects.create(name='tutu') album = Album.objects.create(title='tata', artist=artist) track = Track.objects.create(title='my_track', album=album) audiofile_mapper = AudioFileMapper(delivery_audiofile=self.delivery_audiofile, track=track, disc=self.disc) filename = artist.name + '__' + track.title + '.mp3' path = "/albums/%s/mp3/%s" % (album.pk, filename) produced_audiofile = audiofile_mapper.create() self.assertEqual(path, produced_audiofile.path) self.assertEqual('piste', produced_audiofile.content) self.assertEqual('mp3', produced_audiofile.format) self.assertEqual(self.disc, produced_audiofile.disc) self.assertEqual(114, produced_audiofile.duration) self.assertEqual(8149497, produced_audiofile.size) self.assertEqual(320, produced_audiofile.bitrate)
def build(self): audiofile_mapper = AudioFileMapper(delivery_audiofile=self.delivery_audiofile, track=self.track, disc=self.disc) audiofile = audiofile_mapper.create() shutil.copy(self.delivery_audiofile.path, audiofile.full_path())