Esempio n. 1
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. 2
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. 3
0
 def test_permalink(self):
     artist = ArtistFactory(slug='life+without+buildings',
                            original_slug='Life+Without+Buildings')
     album = AlbumFactory(artist=artist, slug='any+other+city',
                             original_slug='Any+Other+City')
     self.assertEqual(album.permalink,
         'http://www.last.fm/music/Life+Without+Buildings/Any+Other+City')
Esempio n. 4
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. 5
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. 6
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. 7
0
 def test_absolute_url(self):
     artist = ArtistFactory(slug='life+without+buildings',
                            original_slug='Life+Without+Buildings')
     album = AlbumFactory(artist=artist, slug='any+other+city',
                            original_slug='Any+Other+City')
     self.assertEqual(album.get_absolute_url(),
                     '/lastfm/music/life+without+buildings/any+other+city/')
Esempio n. 8
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. 9
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. 10
0
 def test_args_account(self):
     "Should only return Scrobbles by supplied Account"
     account = AccountFactory()
     album2 = AlbumFactory()
     scrobble2 = ScrobbleFactory(account=account, album=album2)
     albums = Album.objects.with_scrobble_counts(account=account)
     self.assertEqual(len(albums), 1)
     self.assertEqual(albums[0], album2)
Esempio n. 11
0
 def test_get_most_recent_scrobble(self):
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     album = AlbumFactory(artist=artist)
     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'))
     self.assertEqual(album.get_most_recent_scrobble(), scrobble2)
Esempio n. 12
0
 def test_get_scrobble_count(self):
     artist = ArtistFactory()
     track = TrackFactory(artist=artist)
     album = AlbumFactory(artist=artist)
     # Scrobbled 2 times:
     ScrobbleFactory.create_batch(2, artist=artist, track=track, album=album)
     # And another Scrobble with different artist/track:
     ScrobbleFactory()
     self.assertEqual(album.get_scrobble_count(), 2)
Esempio n. 13
0
 def test_args_artist(self):
     "Should only return Scrobbles by supplied Artist"
     artist2 = ArtistFactory()
     track2 = TrackFactory(artist=artist2)
     album2 = AlbumFactory(artist=artist2)
     scrobble2 = ScrobbleFactory(artist=artist2, track=track2, album=album2)
     albums = Album.objects.with_scrobble_counts(artist=artist2)
     self.assertEqual(len(albums), 1)
     self.assertEqual(albums[0].artist, artist2)
     self.assertEqual(albums[0].scrobble_count, 1)
Esempio n. 14
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. 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)
Esempio n. 16
0
 def test_updates_existing_album(self):
     "Doesn't create a new Album if it already exists"
     loureed = ArtistFactory(slug='lou+reed')
     AlbumFactory(artist=loureed, slug='transformer')
     self.add_recent_tracks_response()
     results = self.fetcher.fetch()
     albums = Album.objects.filter(slug='transformer')
     self.assertEqual(len(albums), 1)
     self.assertEqual(albums[0].name,'Transformer')
     self.assertEqual(albums[0].slug,'transformer')
     self.assertEqual(albums[0].original_slug,'Transformer')
     self.assertEqual(albums[0].mbid,'4ee40d97-630c-3f0d-9ea2-d49fa253c354')
     self.assertEqual(albums[0].artist, loureed)
Esempio n. 17
0
 def test_default_days(self):
     "Has correct scrobble count context when all days are viewed, the default."
     artist = ArtistFactory()
     album = AlbumFactory(artist=artist)
     scrobble1 = ScrobbleFactory(
         artist=artist,
         album=album,
         post_time=datetime_from_str('2012-10-01 12:00:00'))
     scrobble2 = ScrobbleFactory(
         artist=artist,
         album=album,
         post_time=datetime_from_str('2016-10-01 12:00:00'))
     response = self.client.get(reverse('lastfm:album_list'))
     self.assertEqual(response.context['album_list'][0].scrobble_count, 2)
Esempio n. 18
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. 19
0
 def test_musicbrainz_url(self):
     album = AlbumFactory(mbid='65497352-51ea-40a6-b1f0-1bdff6750369')
     self.assertEqual(album.musicbrainz_url,
         'https://musicbrainz.org/release/65497352-51ea-40a6-b1f0-1bdff6750369')
Esempio n. 20
0
 def test_album_error(self):
     album = AlbumFactory()
     with self.assertRaises(ValueError):
         Album.objects.with_scrobble_counts(album=album)
Esempio n. 21
0
 def test_musicbrainz_url_none(self):
     album = AlbumFactory(mbid='')
     self.assertIsNone(album.musicbrainz_url)
Esempio n. 22
0
 def setUp(self):
     self.artist = ArtistFactory(slug='Lou+Reed')
     self.album = AlbumFactory(slug='New+York', artist=self.artist)
Esempio n. 23
0
 def test_str(self):
     album = AlbumFactory(name='Tallahassee')
     self.assertEqual(str(album), 'Tallahassee')
Esempio n. 24
0
 def test_ordering(self):
     album_1 = AlbumFactory(name='We Shall All Be Healed')
     album_2 = AlbumFactory(name='All Hail West Texas')
     albums = Album.objects.all()
     self.assertEqual(albums[0], album_2)
     self.assertEqual(albums[1], album_1)