Esempio 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)
Esempio 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)
Esempio n. 3
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'))
Esempio n. 4
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')
Esempio n. 5
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/')
Esempio n. 6
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…")
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
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])
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
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)
Esempio n. 23
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'))
Esempio n. 24
0
 def test_str(self):
     track = TrackFactory(name='Dance Music')
     self.assertEqual(str(track), 'Dance Music')
Esempio n. 25
0
 def test_ordering(self):
     track_1 = TrackFactory(name='This Year')
     track_2 = TrackFactory(name='Dance Music')
     tracks = Track.objects.all()
     self.assertEqual(tracks[0], track_2)
     self.assertEqual(tracks[1], track_1)
Esempio n. 26
0
 def test_track_error(self):
     track = TrackFactory()
     with self.assertRaises(ValueError):
         Track.objects.with_scrobble_counts(track=track)
Esempio n. 27
0
 def test_musicbrainz_url(self):
     track = TrackFactory(mbid='330fd2ed-785e-473a-bd9b-ab0b109029c8')
     self.assertEqual(track.musicbrainz_url,
         'https://musicbrainz.org/recording/330fd2ed-785e-473a-bd9b-ab0b109029c8')
Esempio n. 28
0
 def test_musicbrainz_url_none(self):
     track = TrackFactory(mbid='')
     self.assertIsNone(track.musicbrainz_url)
Esempio n. 29
0
 def setUp(self):
     self.artist = ArtistFactory(slug='Lou+Reed')
     self.track = TrackFactory(slug='Hold+On', artist=self.artist)
Esempio n. 30
0
 def setUp(self):
     self.artist = ArtistFactory(name='The Mountain Goats')
     self.track = TrackFactory(name='Dance Music', artist=self.artist)