示例#1
0
 def test_song_favourite_in_the_past(self):
     song = Song(artist='Artist', title='Title')
     favourite = Favourite(from_date=datetime.date(2008, 8, 8),
                           to_date=datetime.date(2011, 11, 11),
                           song=song)
     self.assertFalse(song.is_favourite())
     self.assertEqual(str(favourite),
                      '2008-08-08 - 2011-11-11 | Artist - Title')
示例#2
0
 def test_song_currently_favourite(self):
     song = Song(artist='Artist', title='Title')
     favourite = Favourite(from_date=datetime.date(2010, 10, 10),
                           to_date=datetime.date.max,
                           song=song)
     self.assertTrue(song.is_favourite())
     self.assertEqual(str(favourite),
                      '2010-10-10 - 9999-12-31 | Artist - Title')
示例#3
0
class TestSong(TestCase):
    def setUp(self):
        self.song = Song(artist='Artist', title='Title', time_secs=207.75)

    def test_attributes(self):
        self.assertEqual(self.song.artist, 'Artist')
        self.assertEqual(self.song.title, 'Title')
        self.assertEqual(self.song.album, None)

    def test_str(self):
        self.assertEqual(str(self.song), 'Artist - Title')

    def test_is_favourite(self):
        self.assertFalse(self.song.is_favourite())

    def test_as_dict(self):
        expected = {
            'album': None,
            'artist': 'Artist',
            'location': None,
            'mixtape_vol': None,
            'mixtape_item': None,
            'time_secs': 207.75,
            'title': 'Title',
            'track_num': None,
            'year': None
        }
        self.assertEqual(self.song.as_dict(), expected)

    def test_equality(self):
        song2 = Song(artist='Artist', title='Title', time_secs=207.75)
        self.assertEqual(self.song, song2)
        song3 = Song(artist='Artist', title='Another Title', time_secs=207.75)
        self.assertNotEqual(self.song, song3)

    def test_time_secs_as_int(self):
        self.assertEqual(self.song.time_secs_as_int, 207)

    def test_from_filename(self):
        curdir = os.path.dirname(__file__)
        mp3_file = os.path.join(curdir, 'test_files', 'mp3',
                                'Kinematic - Peyote.mp3')
        song = Song.from_filename(mp3_file, curdir)
        expected = {
            'album': 'Kites',
            'artist': 'Kinematic',
            'location': 'test_files/mp3/Kinematic - Peyote.mp3',
            'mixtape_vol': None,
            'mixtape_item': None,
            'time_secs': 183.51020408163265,
            'title': 'Peyote',
            'track_num': 5,
            'year': None
        }
        self.assertEqual(song.as_dict(), expected)
示例#4
0
 def test_add_song(self):
     song_list = SongList(self.empty_db)
     song = Song(artist='Artist', title='Title', album='Album')
     self.assertEqual(len(song_list), 0)
     self.assertFalse(song in song_list)
     song_list.add_song(song)
     self.assertEqual(len(song_list), 1)
     self.assertTrue(song in song_list)
     self.assertTrue(
         Song(artist='Artist', title='Title', album='Album') in song_list)
     with self.assertRaises(ValueError):
         song_list.add_song(song)
示例#5
0
 def test_add_song_from_filename(self):
     song_list = SongList(self.empty_db)
     file_path = os.path.join(self.mp3_files, 'Kinematic - Peyote.mp3')
     song = Song.from_filename(file_path, music_dir=self.mp3_files)
     self.assertEqual(len(song_list), 0)
     self.assertFalse(song in song_list)
     song_list.add_song(song)
     self.assertEqual(len(song_list), 1)
     self.assertTrue(song in song_list)
     self.assertTrue(
         Song(artist='Kinematic', title='Peyote', album='Kites') in
         song_list)
     with self.assertRaises(ValueError):
         song_list.add_song(song)
     print(song.as_dict())
示例#6
0
 def setUp(self):
     super().setUp()
     self.mp3_files = os.path.join(self.test_files, 'mp3')
     songs = [
         'Kinematic - Peyote.mp3',
         'Roller Genoa - Build My Gallows High.mp3',
         'Alex Cohen - Good Old Times.mp3',
     ]
     self.songs = [
         Song.from_filename(os.path.join(self.mp3_files, s),
                            music_dir=self.mp3_files) for s in songs
     ]
示例#7
0
 def test_from_filename(self):
     curdir = os.path.dirname(__file__)
     mp3_file = os.path.join(curdir, 'test_files', 'mp3',
                             'Kinematic - Peyote.mp3')
     song = Song.from_filename(mp3_file, curdir)
     expected = {
         'album': 'Kites',
         'artist': 'Kinematic',
         'location': 'test_files/mp3/Kinematic - Peyote.mp3',
         'mixtape_vol': None,
         'mixtape_item': None,
         'time_secs': 183.51020408163265,
         'title': 'Peyote',
         'track_num': 5,
         'year': None
     }
     self.assertEqual(song.as_dict(), expected)
示例#8
0
 def setUp(self):
     self.song = Song(artist='Artist', title='Title', time_secs=207.75)
示例#9
0
 def test_equality(self):
     song2 = Song(artist='Artist', title='Title', time_secs=207.75)
     self.assertEqual(self.song, song2)
     song3 = Song(artist='Artist', title='Another Title', time_secs=207.75)
     self.assertNotEqual(self.song, song3)