Exemplo n.º 1
0
    def setUp(self):
        bob = AccountFactory(username='******')
        terry = AccountFactory(username='******')

        self.artist1 = ArtistFactory()
        self.track1 = TrackFactory(artist=self.artist1)
        self.album1 = AlbumFactory(artist=self.artist1)

        self.artist2 = ArtistFactory()
        self.track2 = TrackFactory(artist=self.artist2)

        bobs1 = ScrobbleFactory.create_batch(2,
                                             account=bob,
                                             track=self.track1,
                                             artist=self.artist1,
                                             album=self.album1)
        bobs2 = ScrobbleFactory.create_batch(5,
                                             account=bob,
                                             track=self.track2,
                                             artist=self.artist2)

        terrys1 = ScrobbleFactory.create_batch(3,
                                               account=terry,
                                               track=self.track1,
                                               artist=self.artist1,
                                               album=self.album1)
        terrys2 = ScrobbleFactory.create_batch(7,
                                               account=terry,
                                               track=self.track2,
                                               artist=self.artist2)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def test_absolute_url(self):
     artist = ArtistFactory(slug='the+mountain+goats',
                             original_slug='The+Mountain+Goats')
     track = TrackFactory(slug='dance+music', original_slug='Dance+Music',
                             artist=artist)
     self.assertEqual(track.get_absolute_url(),
                     '/lastfm/music/the+mountain+goats/_/dance+music/')
Exemplo n.º 4
0
 def test_get_scrobble_count(self):
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     # Scrobbled 2 times:
     ScrobbleFactory.create_batch(2, artist=artist, track=track)
     # And another Scrobble with different artist/track:
     ScrobbleFactory()
     self.assertEqual(track.get_scrobble_count(), 2)
Exemplo n.º 5
0
 def test_get_most_recent_scrobble(self):
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     scrobble1 = ScrobbleFactory(artist=artist, track=track,
                         post_time=datetime_from_str('2015-08-11 12:00:00'))
     scrobble2 = ScrobbleFactory(artist=artist, track=track,
                         post_time=datetime_from_str('2015-08-12 12:00:00'))
     self.assertEqual(track.get_most_recent_scrobble(), scrobble2)
Exemplo n.º 6
0
 def test_permalink(self):
     artist = ArtistFactory(slug='the+mountain+goats',
                             original_slug='The+Mountain+Goats')
     track = TrackFactory(slug='dance+music',original_slug='Dance+Music',
                             artist=artist)
     self.assertEqual(track.permalink,
             'http://www.last.fm/music/The+Mountain+Goats/_/Dance+Music')
Exemplo n.º 7
0
 def test_long_titles(self):
     "If artist + track is longer than 255 characters, it gets truncated."
     a = ArtistFactory(name='Drew Danburry')
     t = TrackFactory(artist=a, name="Jerry Spinelli and Patricia Polacco or Every Moment of Every Day We Are Faced With the Decision as to Whether We Will Continue Doing What We Are Doing or Choose a Different Way to Do Things. This, Essentially, Means That It Is Also Our Fault When...")
     scrobble = ScrobbleFactory(artist=a, track=t)
     self.maxDiff = None # To show the full diff.
     self.assertEqual(scrobble.title, "Drew Danburry – Jerry Spinelli and Patricia Polacco or Every Moment of Every Day We Are Faced With the Decision as to Whether We Will Continue Doing What We Are Doing or Choose a Different Way to Do Things. This, Essentially, Means That It Is Also Our…")
Exemplo n.º 8
0
    def setUp(self):
        artist = ArtistFactory()
        track = TrackFactory(artist=artist)
        album = AlbumFactory(artist=artist)

        # Scrobbled 4 times on different days, by 2 different Accounts:
        scrobble1 = ScrobbleFactory(
            artist=artist,
            track=track,
            album=album,
            post_time=datetime_from_str('2015-08-11 12:00:00'))
        scrobble2 = ScrobbleFactory(
            artist=artist,
            track=track,
            album=album,
            post_time=datetime_from_str('2015-08-12 12:00:00'))
        scrobble2 = ScrobbleFactory(
            artist=artist,
            track=track,
            album=album,
            post_time=datetime_from_str('2015-08-13 12:00:00'))
        scrobble4 = ScrobbleFactory(
            artist=artist,
            track=track,
            album=album,
            post_time=datetime_from_str('2015-08-14 12:00:00'))
Exemplo n.º 9
0
    def test_tracks(self):
        artist = ArtistFactory()
        track1 = TrackFactory(artist=artist)
        track2 = TrackFactory(artist=artist)
        album = AlbumFactory(artist=artist)
        # Scrobble track1 once, track2 twice:
        ScrobbleFactory(artist=artist, track=track1, album=album)
        ScrobbleFactory(artist=artist, track=track2, album=album)
        ScrobbleFactory(artist=artist, track=track2, album=album)

        tracks = album.tracks
        self.assertEqual(len(tracks), 2)
        self.assertEqual(tracks[0], track2)
        self.assertEqual(tracks[1], track1)
        self.assertEqual(tracks[0].scrobble_count, 2)
        self.assertEqual(tracks[1].scrobble_count, 1)
Exemplo n.º 10
0
 def test_get_top_tracks_limit(self):
     "Only returns the number of top tracks requested"
     artist = ArtistFactory()
     tracks = TrackFactory.create_batch(4, artist=artist)
     for t in tracks:
         ScrobbleFactory(artist=artist, track=t)
     top_tracks = artist.get_top_tracks(limit=3)
     self.assertEqual(len(top_tracks), 3)
Exemplo n.º 11
0
    def setUp(self):
        self.album1 = AlbumFactory()
        self.artist1 = ArtistFactory()
        self.tracks = TrackFactory.create_batch(11, artist=self.artist1)
        # Extra scrobbles.
        # For artist1, tracks[1] will be 1st, tracks[2] will be 2nd:
        ScrobbleFactory.create_batch(2,
                album=self.album1, artist=self.artist1, track=self.tracks[1])
        ScrobbleFactory.create_batch(1,
                album=self.album1, artist=self.artist1, track=self.tracks[2])

        # But artist2 has a more-scrobbled Track:
        self.album2 = AlbumFactory()
        self.artist2 = ArtistFactory()
        self.track2 = TrackFactory(artist=self.artist2)
        ScrobbleFactory.create_batch(4,
                album=self.album2, artist=self.artist2, track=self.track2)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 def test_args_artist(self):
     "Should only return Scrobbles by supplied Artist"
     artist2 = ArtistFactory()
     track2 = TrackFactory(artist=artist2)
     scrobble2 = ScrobbleFactory(artist=artist2, track=track2)
     tracks = Track.objects.with_scrobble_counts(artist=artist2)
     self.assertEqual(len(tracks), 1)
     self.assertEqual(tracks[0].artist, artist2)
     self.assertEqual(tracks[0].scrobble_count, 1)
Exemplo n.º 14
0
 def test_scrobble_counts(self):
     "Should add a `scrobble_count` aggregate Count to each Track."
     # Add another track, with 1 scrobble, as well as the one in setUp():
     artist2 = ArtistFactory()
     track2 = TrackFactory(artist=artist2)
     scrobble2 = ScrobbleFactory(artist=artist2, track=track2)
     tracks = Track.objects.with_scrobble_counts()
     self.assertEqual(len(tracks), 2)
     self.assertEqual(tracks[0].scrobble_count, 4)
     self.assertEqual(tracks[1].scrobble_count, 1)
Exemplo n.º 15
0
 def test_scrobble_counts(self):
     "Should add a `scrobble_count` aggregate Count to each Album."
     # Add another album, with 1 scrobble, as well as the one in setUp():
     artist2 = ArtistFactory()
     track2 = TrackFactory(artist=artist2)
     album2 = AlbumFactory(artist=artist2)
     scrobble2 = ScrobbleFactory(artist=artist2, track=track2, album=album2)
     albums = Album.objects.with_scrobble_counts()
     self.assertEqual(len(albums), 2)
     self.assertEqual(albums[0].scrobble_count, 4)
     self.assertEqual(albums[1].scrobble_count, 1)
Exemplo n.º 16
0
 def test_args_track(self):
     "Should only return Scrobbles on Albums featuring supplied Track"
     album2 = AlbumFactory()
     track2 = TrackFactory()
     ScrobbleFactory(album=album2, track=track2)
     ScrobbleFactory(album=album2, track=track2)
     albums = Album.objects.with_scrobble_counts(track=track2)
     self.assertEqual(len(albums), 1)
     self.assertEqual(len(albums), 1)
     self.assertEqual(albums[0], album2)
     self.assertEqual(albums[0].scrobble_count, 2)
Exemplo n.º 17
0
 def test_get_top_tracks(self):
     "Returns all tracks, ordered by most-scrobbled first"
     artist = ArtistFactory()
     tracks = TrackFactory.create_batch(3, artist=artist)
     # Scrobble all tracks once...
     for t in tracks:
         ScrobbleFactory(artist=artist, track=t)
     # ... but scrobble one of them an additional time:
     ScrobbleFactory(artist=artist, track=tracks[1])
     top_tracks = artist.get_top_tracks()
     self.assertEqual(len(top_tracks), 3)
     self.assertEqual(top_tracks[0], tracks[1])
Exemplo n.º 18
0
 def test_updates_existing_track(self):
     "Doesn't create a new Track if it already exists"
     loureed = ArtistFactory(slug='lou+reed')
     TrackFactory(artist=loureed, slug='make+up')
     self.add_recent_tracks_response()
     results = self.fetcher.fetch()
     tracks = Track.objects.filter(slug='make+up')
     self.assertEqual(len(tracks), 1)
     self.assertEqual(tracks[0].name,'Make Up')
     self.assertEqual(tracks[0].slug,'make+up')
     self.assertEqual(tracks[0].original_slug,'Make+Up')
     self.assertEqual(tracks[0].mbid,'8e73b23a-6a01-4743-b414-047974f66e22')
     self.assertEqual(tracks[0].artist, loureed)
Exemplo n.º 19
0
 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])
Exemplo n.º 20
0
 def test_default_days(self):
     "Has correct scrobble count context when all days are viewed, the default."
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     scrobble1 = ScrobbleFactory(
         artist=artist,
         track=track,
         post_time=datetime_from_str('2012-10-01 12:00:00'))
     scrobble2 = ScrobbleFactory(
         artist=artist,
         track=track,
         post_time=datetime_from_str('2016-10-01 12:00:00'))
     response = self.client.get(reverse('lastfm:artist_list'))
     self.assertEqual(response.context['artist_list'][0].scrobble_count, 2)
Exemplo n.º 21
0
 def test_args_album(self):
     "Only aggregates scrobble_counts for a particular album."
     artist2 = ArtistFactory()
     album1 = AlbumFactory()
     album2 = AlbumFactory()
     track = TrackFactory()
     ScrobbleFactory(album=album1, artist=self.artist, track=track)
     ScrobbleFactory(album=album1, artist=self.artist, track=track)
     ScrobbleFactory(album=album1, artist=artist2, track=track)
     ScrobbleFactory(album=album2, artist=self.artist, track=track)
     artists = Artist.objects.with_scrobble_counts(album=album1)
     self.assertEqual(len(artists), 2)
     self.assertEqual(artists[0].scrobble_count, 2)
     self.assertEqual(artists[1].scrobble_count, 1)
Exemplo n.º 22
0
 def test_7_days(self):
     "Has correct scrobble count context when a restricted number of days are viewed."
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     scrobble1 = ScrobbleFactory(
         artist=artist,
         track=track,
         post_time=datetime_from_str('2012-10-01 12:00:00'))
     scrobble2 = ScrobbleFactory(
         artist=artist,
         track=track,
         post_time=datetime_from_str('2016-10-01 12:00:00'))
     response = self.client.get("%s?days=7" % reverse('lastfm:track_list'))
     self.assertEqual(response.context['track_list'][0].scrobble_count, 1)
Exemplo n.º 23
0
 def test_context(self):
     "Sends the correct data to the templates"
     accounts = AccountFactory.create_batch(2)
     tracks = TrackFactory.create_batch(3)
     response = self.client.get(reverse('lastfm:track_list'))
     self.assertIn('account_list', response.context)
     self.assertEqual(len(response.context['account_list']), 2)
     self.assertIn('track_list', response.context)
     self.assertEqual(len(response.context['track_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')
Exemplo n.º 24
0
 def test_args_album(self):
     "Only aggregates scrobble_counts in supplied album."
     album1 = AlbumFactory()
     album2 = AlbumFactory()
     track1 = TrackFactory()
     ScrobbleFactory.create_batch(2, album=album1, track=self.track)
     ScrobbleFactory.create_batch(1, album=album1, track=track1)
     ScrobbleFactory.create_batch(1, album=album2, track=self.track)
     tracks = Track.objects.with_scrobble_counts(album=album1)
     self.assertEqual(len(tracks), 2)
     self.assertEqual(tracks[0].scrobble_count, 2)
     self.assertEqual(tracks[0], self.track)
     self.assertEqual(tracks[1].scrobble_count, 1)
     self.assertEqual(tracks[1], track1)
Exemplo n.º 25
0
    def setUp(self):
        self.artists = ArtistFactory.create_batch(11)
        self.tracks = []
        # Each artist has one track, scrobbled once:
        for artist in self.artists:
            track = TrackFactory(artist=artist)
            self.tracks.append(track)
            ScrobbleFactory(artist=artist, track=track)

        # Extra scrobbles.
        # For tracks[1] will be 1st, tracks[2] will be 2nd:
        ScrobbleFactory.create_batch(2,
                                artist=self.artists[1], track=self.tracks[1])
        ScrobbleFactory.create_batch(1,
                                artist=self.artists[2], track=self.tracks[2])
Exemplo n.º 26
0
    def test_albums(self):
        artist = ArtistFactory()
        track = TrackFactory(artist=artist)
        album1 = AlbumFactory(artist=artist)
        album2 = AlbumFactory(artist=artist)
        # Scrobble album1 once, album2 twice:
        ScrobbleFactory(artist=artist, track=track, album=album1)
        ScrobbleFactory(artist=artist, track=track, album=album2)
        ScrobbleFactory(artist=artist, track=track, album=album2)

        albums = track.albums
        self.assertEqual(len(albums), 2)
        self.assertEqual(albums[0], album2)
        self.assertEqual(albums[1], album1)
        self.assertEqual(albums[0].scrobble_count, 2)
        self.assertEqual(albums[1].scrobble_count, 1)
Exemplo n.º 27
0
 def test_context(self):
     "Sends the correct data to the templates"
     accounts = AccountFactory.create_batch(2)
     tracks = TrackFactory.create_batch(3)
     response = self.client.get(reverse('lastfm:track_list'))
     self.assertIn('account_list', response.context)
     self.assertEqual(len(response.context['account_list']), 2)
     self.assertIn('track_list', response.context)
     self.assertEqual(len(response.context['track_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')
Exemplo n.º 28
0
    def test_updates_existing_scrobbles(self):
        "Updates existing scrobble objects"
        # Make our existing scrobble:
        artist = ArtistFactory(slug='lou+reed')
        track = TrackFactory(artist=artist, slug='make+up')
        post_time = datetime.datetime.strptime(
                        '2016-09-22 09:23:33', '%Y-%m-%d %H:%M:%S'
                    ).replace(tzinfo=pytz.utc)
        scrobble = ScrobbleFactory(account=self.account,
                                   track=track,
                                   post_time=post_time)

        self.add_recent_tracks_response()
        results = self.fetcher.fetch(fetch_type='all')

        scrobbles = Scrobble.objects.all()
        # We have this many finished scrobbles in our JSON fixture:
        self.assertEqual(len(scrobbles), 3)
        scrobble_reloaded = Scrobble.objects.get(artist=artist)
        self.assertEqual(scrobble.pk, scrobble_reloaded.pk)
Exemplo n.º 29
0
    def setUp(self):
        self.artist = ArtistFactory()
        self.track = TrackFactory(artist=self.artist)

        # Scrobbled 4 times on different days:
        scrobble1 = ScrobbleFactory(
            artist=self.artist,
            track=self.track,
            post_time=datetime_from_str('2015-08-11 12:00:00'))
        scrobble2 = ScrobbleFactory(
            artist=self.artist,
            track=self.track,
            post_time=datetime_from_str('2015-08-12 12:00:00'))
        scrobble2 = ScrobbleFactory(
            artist=self.artist,
            track=self.track,
            post_time=datetime_from_str('2015-08-13 12:00:00'))
        scrobble4 = ScrobbleFactory(
            artist=self.artist,
            track=self.track,
            post_time=datetime_from_str('2015-08-14 12:00:00'))
Exemplo n.º 30
0
    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)
Exemplo n.º 31
0
 def setUp(self):
     self.artist = ArtistFactory(slug='Lou+Reed')
     self.track = TrackFactory(slug='Hold+On', artist=self.artist)
Exemplo n.º 32
0
 def test_track_error(self):
     track = TrackFactory()
     with self.assertRaises(ValueError):
         Track.objects.with_scrobble_counts(track=track)