コード例 #1
0
 def test_for_account(self):
     "Should only count scrobbles by the supplied Account."
     account = AccountFactory()
     # Our one scrobble by this account:
     ScrobbleFactory(account=account,
                     artist=self.artist1, track=self.tracks[1])
     tracks = ditto_lastfm.top_tracks(account=account, limit='all')
     self.assertEqual(len(tracks), 1)
     self.assertEqual(tracks[0], self.tracks[1])
     self.assertEqual(tracks[0].scrobble_count, 1)
コード例 #2
0
    def test_for_year(self):
        "Should return only tracks from the requested year."
        # 2 scrobbles in this year:
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2015-01-01 12:00:00'))
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2015-12-31 12:00:00'))
        # 1 scrobble in this year:
        ScrobbleFactory(track=self.tracks[2],
                        post_time=datetime_from_str('2016-03-01 12:00:00'))

        tracks = ditto_lastfm.top_tracks(period='year',
                        date=datetime_from_str('2015-09-01 00:00:00'))
        self.assertEqual(len(tracks), 1)
        self.assertEqual(tracks[0].scrobble_count, 2)
コード例 #3
0
    def test_for_month(self):
        "Should return only tracks from the requested month."
        # 2 scrobbles in this month:
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2016-09-01 12:00:00'))
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2016-09-30 12:00:00'))
        # 1 scrobble in this month:
        ScrobbleFactory(track=self.tracks[2],
                        post_time=datetime_from_str('2016-10-01 12:00:00'))

        tracks = ditto_lastfm.top_tracks(period='month',
                        date=datetime_from_str('2016-09-15 00:00:00'))
        self.assertEqual(len(tracks), 1)
        self.assertEqual(tracks[0].scrobble_count, 2)
コード例 #4
0
    def test_for_day_with_date(self):
        "Should return only tracks from the requested day, using date."
        # 2 scrobbles on this day:
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2016-10-01 00:00:00'))
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2016-10-01 23:59:59'))
        # 1 scrobble on this day:
        ScrobbleFactory(track=self.tracks[2],
                        post_time=datetime_from_str('2016-10-02 12:00:00'))

        tracks = ditto_lastfm.top_tracks(period='day',
                        date=datetime_from_str('2016-10-01 00:00:00').date())
        self.assertEqual(len(tracks), 1)
        self.assertEqual(tracks[0].scrobble_count, 2)
コード例 #5
0
    def test_for_week_monday_start(self):
        "Should return only tracks from the requested week (Monday start)."
        # 2 scrobbles on this day:
        # 2017-09-04 is a Monday
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2017-09-04 00:00:00'))
        ScrobbleFactory(track=self.tracks[1],
                        post_time=datetime_from_str('2017-09-10 23:59:59'))
        # 1 scrobble on this day:
        ScrobbleFactory(track=self.tracks[2],
                        post_time=datetime_from_str('2017-09-11 12:00:00'))

        tracks = ditto_lastfm.top_tracks(period='week',
                        date=datetime_from_str('2017-09-07 00:00:00'))
        self.assertEqual(len(tracks), 1)
        self.assertEqual(tracks[0].scrobble_count, 2)
コード例 #6
0
 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_tracks(date=d, period='bob')
コード例 #7
0
 def test_date_error(self):
     "Should raise TypeError if invalid date is supplied."
     with self.assertRaises(TypeError):
         ditto_lastfm.top_tracks(date='bob', period='month')
コード例 #8
0
 def test_limit_error(self):
     "Should raise ValueError if `limit` is invalid."
     with self.assertRaises(ValueError):
         ditto_lastfm.top_tracks(artist=self.artist1, limit='bob')
コード例 #9
0
 def test_artist_error(self):
     "Should raise TypeError if invalid Artist is supplied."
     with self.assertRaises(TypeError):
         ditto_lastfm.top_tracks(artist='bob', limit=3)
コード例 #10
0
 def test_for_artist(self):
     "Should return only the Artist's tracks."
     tracks = ditto_lastfm.top_tracks(artist=self.artist1, limit='all')
     self.assertEqual(len(tracks), 2)
     self.assertEqual(tracks[0], self.tracks[1])
     self.assertEqual(tracks[1], self.tracks[2])
コード例 #11
0
 def test_for_album(self):
     "Should return only the tracks on that Album."
     tracks = ditto_lastfm.top_tracks(album=self.album1, limit='all')
     self.assertEqual(len(tracks), 2)
     self.assertEqual(tracks[0], self.tracks[1])
     self.assertEqual(tracks[1], self.tracks[2])
コード例 #12
0
 def test_limit_all(self):
     "Should return all tracks if `limit` is 'all'."
     tracks = ditto_lastfm.top_tracks(limit='all')
     self.assertEqual(len(tracks), 12)
コード例 #13
0
 def test_limit(self):
     "Should return `limit` tracks."
     tracks = ditto_lastfm.top_tracks(limit=3)
     self.assertEqual(len(tracks), 3)
コード例 #14
0
 def test_default_limit(self):
     "By default should return 10 tracks."
     tracks = ditto_lastfm.top_tracks()
     self.assertEqual(len(tracks), 10)
コード例 #15
0
 def test_order(self):
     "The most scrobbled tracks should be first."
     tracks = ditto_lastfm.top_tracks()
     self.assertEqual(tracks[0], self.track2)
     self.assertEqual(tracks[1], self.tracks[1])
     self.assertEqual(tracks[2], self.tracks[2])