def test_for_account(self): "Should only count scrobbles by supplied Account." account = AccountFactory() # Our 1 scrobble by this account: ScrobbleFactory(account=account, artist=self.artist1, track=self.tracks[1], album=self.albums[1]) albums = ditto_lastfm.top_albums(account=account, limit='all') self.assertEqual(len(albums), 1) self.assertEqual(albums[0], self.albums[1]) self.assertEqual(albums[0].scrobble_count, 1)
def test_for_day_with_date(self): "Should return only albums from the requested day, using date." # 2 scrobbles on this day: ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2016-10-01 00:00:00')) ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2016-10-01 23:59:59')) # 1 scrobble on this day: ScrobbleFactory(track=self.tracks[2], album=self.albums[2], post_time=datetime_from_str('2016-10-02 12:00:00')) albums = ditto_lastfm.top_albums(period='day', date=datetime_from_str('2016-10-01 00:00:00').date()) self.assertEqual(len(albums), 1) self.assertEqual(albums[0].scrobble_count, 2)
def test_for_year(self): "Should return only albums from the requested year." # 2 scrobbles in this year: ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2015-01-01 12:00:00')) ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2015-12-31 12:00:00')) # 1 scrobble in this year: ScrobbleFactory(track=self.tracks[2], album=self.albums[2], post_time=datetime_from_str('2016-03-01 12:00:00')) albums = ditto_lastfm.top_albums(period='year', date=datetime_from_str('2015-09-01 00:00:00')) self.assertEqual(len(albums), 1) self.assertEqual(albums[0].scrobble_count, 2)
def test_for_month(self): "Should return only albums from the requested month." # 2 scrobbles in this month: ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2016-09-01 12:00:00')) ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2016-09-30 12:00:00')) # 1 scrobble in this month: ScrobbleFactory(track=self.tracks[2], album=self.albums[2], post_time=datetime_from_str('2016-10-01 12:00:00')) albums = ditto_lastfm.top_albums(period='month', date=datetime_from_str('2016-09-15 00:00:00')) self.assertEqual(len(albums), 1) self.assertEqual(albums[0].scrobble_count, 2)
def test_for_week_sunday_start(self): "Should return only albums from the requested week (Sunday start)." # 2 scrobble in this week: # 2017-09-03 is a Sunday ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2017-09-03 12:00:00')) ScrobbleFactory(track=self.tracks[1], album=self.albums[1], post_time=datetime_from_str('2017-09-09 12:00:00')) # 1 scrobble in this week: ScrobbleFactory(track=self.tracks[2], album=self.albums[2], post_time=datetime_from_str('2017-09-10 12:00:00')) albums = ditto_lastfm.top_albums(period='week', date=datetime_from_str('2017-09-07 00:00:00')) self.assertEqual(len(albums), 1) self.assertEqual(albums[0].scrobble_count, 2)
def test_for_artist(self): "Should only return the artist's albums" albums = ditto_lastfm.top_albums(artist=self.artist1, limit='all') self.assertEqual(len(albums), 11) self.assertEqual(albums[0], self.albums[1]) self.assertEqual(albums[1], self.albums[2])
def test_limit_all(self): "Should return all albums if `limit` is 'all'." albums = ditto_lastfm.top_albums(limit='all') self.assertEqual(len(albums), 12)
def test_limit(self): "Should return `limit` albums." albums = ditto_lastfm.top_albums(limit=3) self.assertEqual(len(albums), 3)
def test_default_limit(self): "By default should return 10 albums." albums = ditto_lastfm.top_albums() self.assertEqual(len(albums), 10)
def test_order(self): "The most scrobbled albums should be first." albums = ditto_lastfm.top_albums() self.assertEqual(albums[0], self.album2) self.assertEqual(albums[1], self.albums[1]) self.assertEqual(albums[2], self.albums[2])
def test_period_error(self): "Should raise TypeError if invalid period is supplied." d = datetime_from_str('2016-10-24 12:00:00') with self.assertRaises(TypeError): ditto_lastfm.top_albums(date=d, period='bob')
def test_date_error(self): "Should raise TypeError if invalid date is supplied." with self.assertRaises(TypeError): ditto_lastfm.top_albums(date='bob', period='month')
def test_limit_error(self): "Should raise ValueError if `limit` is invalid." with self.assertRaises(ValueError): ditto_lastfm.top_albums(artist=self.artist1, limit='bob')
def test_artist_error(self): "Should raise TypeError if invalid Artist is supplied." with self.assertRaises(TypeError): ditto_lastfm.top_albums(artist='bob', limit=3)