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')
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')
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)
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)
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())
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 ]
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)
def setUp(self): self.song = Song(artist='Artist', title='Title', time_secs=207.75)
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)