Exemple #1
0
    def setUp(self):
        super(SongModelTest, self).setUp()

        self.artist = Artist.objects.create(name='The Artist')
        album = Album.objects.create(title='The Album',
                                     artist=self.artist,
                                     cover=self.cover_art,
                                     cover_file_type='jpg')
        self.song = Song(title='The Song', album=album, bitrate=128000,
                         filetype='ogg', first_save=True,
                         filefield=File(open(self.media_file.name)))
        self.song.save()
Exemple #2
0
class SongModelTest(ModelTest):

    def setUp(self):
        super(SongModelTest, self).setUp()

        self.artist = Artist.objects.create(name='The Artist')
        album = Album.objects.create(title='The Album',
                                     artist=self.artist,
                                     cover=self.cover_art,
                                     cover_file_type='jpg')
        self.song = Song(title='The Song', album=album, bitrate=128000,
                         filetype='ogg', first_save=True,
                         filefield=File(open(self.media_file.name)))
        self.song.save()

    def test_save_new_song_creates_file_in_media_directory(self):
        filename = os.path.join(
            self.media_dir, 'T', 'The Artist', 'The Album', 'The Song.ogg')

        self.assertEqual(os.listdir(self.media_dir), ['T'])
        self.assertTrue(os.path.exists(filename))
        self.assertEqual(open(self.media_file.name).read(),
                         open(filename).read())

    def test_save_song_without_change_is_idempotent(self):
        self.assertEqual(self.song.title, 'The Song')
        self.assertEqual(self.song.album.title, 'The Album')
        self.assertEqual(self.song.album.artist.name, 'The Artist')
        self.assertEqual(self.song.filefield.name,
                         'T/The Artist/The Album/The Song.ogg')
        self.assertTrue(os.path.exists(full_path(self.song.filefield.name)))

        original_content = self.song.filefield.read()

        self.song.save()

        self.assertEqual(self.song.title, 'The Song')
        self.assertEqual(self.song.album.title, 'The Album')
        self.assertEqual(self.song.album.artist.name, 'The Artist')
        self.assertEqual(self.song.filefield.name,
                         'T/The Artist/The Album/The Song.ogg')
        self.assertTrue(os.path.exists(full_path(self.song.filefield.name)))

        self.song.filefield.seek(0)
        current_content = self.song.filefield.read()

        self.assertEqual(original_content, current_content)

    def test_leading_zero_for_single_digit_track(self):
        self.song.track = '1'
        self.song.save()
        self.assertNotEqual(self.song.track, '1')
        self.assertEqual(self.song.track, '01')