def setUp(self):
        self.artist1 = ArtistFactory()
        self.tracks = TrackFactory.create_batch(11, artist=self.artist1)
        self.albums = AlbumFactory.create_batch(11, artist=self.artist1)
        # Scrobble each album/track once:
        for idx, track in enumerate(self.tracks):
            ScrobbleFactory(artist=self.artist1,
                            track=track,
                            album=self.albums[idx])

        # Extra scrobbles.
        # For artist1, tracks[1] will be 1st, tracks[2] will be 2nd:
        ScrobbleFactory.create_batch(2,
                                     artist=self.artist1,
                                     track=self.tracks[1],
                                     album=self.albums[1])
        ScrobbleFactory.create_batch(1,
                                     artist=self.artist1,
                                     track=self.tracks[2],
                                     album=self.albums[2])

        # But artist2 has a more scrobbled album:
        self.artist2 = ArtistFactory()
        self.track2 = TrackFactory(artist=self.artist2)
        self.album2 = AlbumFactory(artist=self.artist2)
        ScrobbleFactory.create_batch(4,
                                     artist=self.artist2,
                                     track=self.track2,
                                     album=self.album2)
 def test_get_top_albums_limit(self):
     "Only returns the number of top albums requested"
     artist = ArtistFactory()
     albums = AlbumFactory.create_batch(4, artist=artist)
     tracks = TrackFactory.create_batch(4, artist=artist)
     for idx, t in enumerate(tracks):
         ScrobbleFactory(artist=artist, track=t, album=albums[idx])
     top_albums = artist.get_top_albums(limit=3)
     self.assertEqual(len(top_albums), 3)
 def test_context(self):
     "Sends the correct data to the templates"
     accounts = AccountFactory.create_batch(2)
     albums = AlbumFactory.create_batch(3)
     response = self.client.get(reverse('lastfm:album_list'))
     self.assertIn('account_list', response.context)
     self.assertEqual(len(response.context['account_list']), 2)
     self.assertIn('album_list', response.context)
     self.assertEqual(len(response.context['album_list']), 3)
     self.assertIn('valid_days', response.context)
     self.assertEqual(response.context['valid_days'],
                     ['7', '30', '90', '180', '365', 'all',])
     self.assertIn('current_days', response.context)
     self.assertEqual(response.context['current_days'], 'all')
 def test_get_top_albums(self):
     "Returns all albums, ordered by most-scrobbled first"
     artist = ArtistFactory()
     albums = AlbumFactory.create_batch(3, artist=artist)
     # NB, Tracks & Albums are only associated via Scrobbles, not directly:
     tracks = TrackFactory.create_batch(3, artist=artist)
     # Scrobble all tracks+albums once...
     for idx, t in enumerate(tracks):
         ScrobbleFactory(artist=artist, track=t, album=albums[idx])
     # ... but scrobble one of them an additional time:
     ScrobbleFactory(artist=artist, track=tracks[1], album=albums[1])
     top_albums = artist.get_top_albums()
     self.assertEqual(len(top_albums), 3)
     self.assertEqual(top_albums[0], albums[1])
Exemple #5
0
 def test_context(self):
     "Sends the correct data to the templates"
     accounts = AccountFactory.create_batch(2)
     albums = AlbumFactory.create_batch(3)
     response = self.client.get(reverse('lastfm:album_list'))
     self.assertIn('account_list', response.context)
     self.assertEqual(len(response.context['account_list']), 2)
     self.assertIn('album_list', response.context)
     self.assertEqual(len(response.context['album_list']), 3)
     self.assertIn('valid_days', response.context)
     self.assertEqual(response.context['valid_days'], [
         '7',
         '30',
         '90',
         '180',
         '365',
         'all',
     ])
     self.assertIn('current_days', response.context)
     self.assertEqual(response.context['current_days'], 'all')
    def setUp(self):
        self.artist1 = ArtistFactory()
        self.tracks = TrackFactory.create_batch(11, artist=self.artist1)
        self.albums = AlbumFactory.create_batch(11, artist=self.artist1)
        # Scrobble each album/track once:
        for idx, track in enumerate(self.tracks):
            ScrobbleFactory(artist=self.artist1,
                            track=track,
                            album=self.albums[idx])

        # Extra scrobbles.
        # For artist1, tracks[1] will be 1st, tracks[2] will be 2nd:
        ScrobbleFactory.create_batch(2, artist=self.artist1,
                                    track=self.tracks[1], album=self.albums[1])
        ScrobbleFactory.create_batch(1, artist=self.artist1,
                                    track=self.tracks[2], album=self.albums[2])

        # But artist2 has a more scrobbled album:
        self.artist2 = ArtistFactory()
        self.track2 = TrackFactory(artist=self.artist2)
        self.album2 = AlbumFactory(artist=self.artist2)
        ScrobbleFactory.create_batch(4, artist=self.artist2,
                                track=self.track2, album=self.album2)