Пример #1
0
    def should_return_most_played_genre_from_selected_date(self):
        most_played = GenreFactory()
        second_most_played = GenreFactory()
        entries = [
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[ArtistFactory(genres=[most_played])]))),
            PlaylistHistoryFactory(
                created=datetime.datetime(2014, 1, 1, tzinfo=tzutc()),
                track=TrackFactory(album=AlbumWithArtist(artists=[
                    ArtistFactory(genres=[second_most_played, most_played])
                ]))),
        ]
        db.session.add_all(entries)
        db.session.commit()

        url = url_for('player.stats', **{'from': '2015-06-01'})
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['most_played_genres'] == [
            {
                'name': most_played.name,
                'total': 1
            },
        ]
Пример #2
0
    def should_return_most_played_artist_from_selected_date(self):
        user = UserFactory()
        most_played = ArtistFactory()
        second_most_played = ArtistFactory()
        entries = [
            user,
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[most_played])),
                                   user=user),
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[second_most_played]))),
            PlaylistHistoryFactory(
                created=datetime.datetime(2014, 1, 1, tzinfo=tzutc()),
                track=TrackFactory(album=AlbumWithArtist(
                    artists=[second_most_played, most_played])),
                user=user),
        ]
        db.session.add_all(entries)
        db.session.commit()

        url = url_for('users.stats', pk=user.id, **{'from': '2015-06-01'})
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['most_played_artists'] == [
            {
                'artist': ArtistSerializer().serialize(most_played),
                'total': 1
            },
        ]
Пример #3
0
    def should_return_most_played_genre_from_the_beginning_of_the_age(self):
        most_played = GenreFactory()
        second_most_played = GenreFactory()
        entries = [
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[ArtistFactory(genres=[most_played])]))),
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[
                    ArtistFactory(genres=[second_most_played, most_played])
                ]))),
        ]
        db.session.add_all(entries)
        db.session.commit()

        url = url_for('player.stats')
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['most_played_genres'] == [
            {
                'name': most_played.name,
                'total': 2
            },
            {
                'name': second_most_played.name,
                'total': 1
            },
        ]
Пример #4
0
    def should_return_most_played_artist_from_the_beginning_of_the_age(self):
        user = UserFactory()
        most_played = ArtistFactory()
        second_most_played = ArtistFactory()
        entries = [
            user,
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[most_played])),
                                   user=user),
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[second_most_played, most_played])),
                                   user=user),
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[second_most_played]))),
        ]
        db.session.add_all(entries)
        db.session.commit()

        url = url_for('users.stats', pk=user.id)
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['most_played_artists'] == [
            {
                'artist': ArtistSerializer().serialize(most_played),
                'total': 2
            },
            {
                'artist': ArtistSerializer().serialize(second_most_played),
                'total': 1
            },
        ]
Пример #5
0
    def should_returns_list_of_genres_in_queue(self):
        genres = GenreFactory.create_batch(2)
        track1 = TrackFactory(album=AlbumWithArtist(
            artists=[ArtistFactory(genres=genres)]))
        track2 = TrackFactory(album=AlbumWithArtist(
            artists=[ArtistFactory(genres=[genres[0]])]))
        tracks = [track1, track2]
        db.session.add_all(tracks)
        db.session.commit()

        for track in tracks:
            self.redis.rpush(
                config.PLAYLIST_REDIS_KEY,
                json.dumps({
                    'uri': track.spotify_uri,
                    'user': '******'
                }))

        url = url_for('player.queue-meta')
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['genres'] == {
            genres[0].name: 2,
            genres[1].name: 1
        }
Пример #6
0
    def should_return_most_played_artist_in_selected_time_window(self):
        most_played = ArtistFactory()
        entries = [
            PlaylistHistoryFactory(created=datetime.datetime(2015,
                                                             5,
                                                             1,
                                                             tzinfo=tzutc()),
                                   track=TrackFactory(album=AlbumWithArtist(
                                       artists=[most_played]))),
            PlaylistHistoryFactory(
                created=datetime.datetime(2015, 3, 1, tzinfo=tzutc())),
            PlaylistHistoryFactory(
                created=datetime.datetime(2015, 7, 1, tzinfo=tzutc())),
        ]
        db.session.add_all(entries)
        db.session.commit()

        url = url_for('player.stats', **{
            'to': '2015-06-01',
            'from': '2015-04-01'
        })
        response = self.client.get(url)

        assert response.status_code == 200
        assert response.json['most_played_artists'] == [
            {
                'artist': ArtistSerializer().serialize(most_played),
                'total': 1
            },
        ]
Пример #7
0
    def should_update_artist_genres(self):
        self.get_artist_genres.side_effect = EchoNestError

        a = ArtistFactory()

        db.session.add(a)
        db.session.commit()

        result = update_genres.delay(a.id)

        assert result.wait() is False
        self.get_artist_genres.assert_called_once_with(a.spotify_uri)
Пример #8
0
    def should_udpate_artist_genres(self):
        self.get_artist_genres.return_value = ['foo', 'bar']

        a = ArtistFactory()

        db.session.add(a)
        db.session.commit()

        result = update_genres.delay(a.id)
        artist = Artist.query.all()[0]

        assert result.wait() is True
        assert Genre.query.filter(Genre.name == 'foo').first() in artist.genres
        assert Genre.query.filter(Genre.name == 'bar').first() in artist.genres
        self.get_artist_genres.assert_called_once_with(artist.spotify_uri)
Пример #9
0
    def should_update_existing_artist(self):
        artist = ArtistFactory(name='Foo',
                               spotify_uri=TRACK_DATA['artists'][0]['uri'])

        db.session.add(artist)
        db.session.commit()

        add.delay(TRACK_DATA, self.user.id)

        artist = Artist.query.one()

        assert not artist.name == 'Foo'
        assert artist.name == TRACK_DATA['artists'][0]['name']
        assert artist.spotify_uri == TRACK_DATA['artists'][0]['uri']
        assert Album.query.first() in artist.albums
Пример #10
0
    def should_return_non_false_values_when_something_is_in_queue(self):
        tracks = TrackFactory.create_batch(
            3,
            album=AlbumWithArtist(
                artists=[ArtistFactory(genres=GenreFactory.create_batch(2))]))
        db.session.add_all(tracks)
        db.session.commit()

        for track in tracks:
            self.redis.rpush(
                config.PLAYLIST_REDIS_KEY,
                json.dumps({
                    'uri': track.spotify_uri,
                    'user': '******'
                }))
        url = url_for('player.queue-meta')
        response = self.client.get(url)
        assert response.json['total']
        assert response.json['genres']
        assert response.json['users']
        assert response.json['play_time']