예제 #1
0
    def should_return_most_played_djs_from_the_beginning_of_the_age(self):
        most_played = UserFactory()
        second_most_played = UserFactory()
        entries = [
            PlaylistHistoryFactory(user=most_played),
            PlaylistHistoryFactory(user=most_played),
            PlaylistHistoryFactory(user=second_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_active_djs'] == [
            {
                'user': UserSerializer().serialize(most_played),
                'total': 2
            },
            {
                'user': UserSerializer().serialize(second_most_played),
                'total': 1
            },
        ]
예제 #2
0
    def should_return_user_played_time_from_selected_date(self):
        most_played = UserFactory()
        second_most_played = UserFactory()
        entries = [
            PlaylistHistoryFactory(user=most_played,
                                   track=TrackFactory(duration=1000)),
            PlaylistHistoryFactory(user=most_played,
                                   created=datetime.datetime(2014,
                                                             1,
                                                             1,
                                                             tzinfo=tzutc()),
                                   track=TrackFactory(duration=500)),
            PlaylistHistoryFactory(user=second_most_played,
                                   track=TrackFactory(duration=700)),
        ]
        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['total_play_time_per_user'] == [
            {
                'user': UserSerializer().serialize(most_played),
                'total': 1000
            },
            {
                'user': UserSerializer().serialize(second_most_played),
                'total': 700
            },
        ]
예제 #3
0
    def should_return_user_played_time_from_the_beginning_of_the_age(self):
        most_played = UserFactory()
        second_most_played = UserFactory()
        entries = [
            PlaylistHistoryFactory(user=most_played,
                                   track=TrackFactory(duration=1000)),
            PlaylistHistoryFactory(user=most_played,
                                   track=TrackFactory(duration=500)),
            PlaylistHistoryFactory(user=second_most_played,
                                   track=TrackFactory(duration=700)),
        ]
        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['total_play_time_per_user'] == [
            {
                'user': UserSerializer().serialize(most_played),
                'total': 1500
            },
            {
                'user': UserSerializer().serialize(second_most_played),
                'total': 700
            },
        ]
예제 #4
0
    def should_return_most_played_djs_in_selected_time_window(self):
        most_played = UserFactory()
        entries = [
            PlaylistHistoryFactory(user=most_played,
                                   created=datetime.datetime(2015,
                                                             5,
                                                             1,
                                                             tzinfo=tzutc())),
            PlaylistHistoryFactory(
                created=datetime.datetime(2015, 7, 1, tzinfo=tzutc())),
            PlaylistHistoryFactory(
                created=datetime.datetime(2015, 3, 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_active_djs'] == [
            {
                'user': UserSerializer().serialize(most_played),
                'total': 1
            },
        ]
예제 #5
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
            },
        ]
예제 #6
0
    def should_return_most_played_genre_from_the_beginning_of_the_age(self):
        user = UserFactory()
        most_played = GenreFactory()
        second_most_played = GenreFactory()
        entries = [
            user,
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[ArtistFactory(genres=[most_played])])),
                                   user=user),
            PlaylistHistoryFactory(
                track=TrackFactory(album=AlbumWithArtist(artists=[
                    ArtistFactory(genres=[second_most_played, most_played])
                ])),
                user=user),
            PlaylistHistoryFactory(track=TrackFactory(album=AlbumWithArtist(
                artists=[ArtistFactory(genres=[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_genres'] == [
            {
                'name': most_played.name,
                'total': 2
            },
            {
                'name': second_most_played.name,
                'total': 1
            },
        ]
예제 #7
0
    def should_return_played_tracks_from_the_beginning_of_the_age(self):
        user = UserFactory()
        most_played = TrackFactory()
        second_most_played = TrackFactory()
        entries = [
            user,
            PlaylistHistoryFactory(track=most_played, user=user),
            PlaylistHistoryFactory(track=most_played, user=user),
            PlaylistHistoryFactory(track=second_most_played, user=user),
            PlaylistHistoryFactory(track=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_tracks'] == [
            {
                'track': FMTrackSerializer().serialize(most_played),
                'total': 2
            },
            {
                'track': FMTrackSerializer().serialize(second_most_played),
                'total': 1
            },
        ]
예제 #8
0
    def should_return_total_plays_from_the_beginning_of_the_age(self):
        user = UserFactory()
        entries = [
            user,
            PlaylistHistoryFactory(user=user),
            PlaylistHistoryFactory(user=user),
            PlaylistHistoryFactory()
        ]
        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['total_plays'] == 2
예제 #9
0
    def should_return_total_plays_from_selected_date(self):
        user = UserFactory()
        entries = [
            user,
            PlaylistHistoryFactory(user=user),
            PlaylistHistoryFactory(user=user),
            PlaylistHistoryFactory(),
            PlaylistHistoryFactory(
                user=user,
                created=datetime.datetime(2014, 1, 1, tzinfo=tzutc()),
            )
        ]
        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['total_plays'] == 2
예제 #10
0
    def should_return_played_time_from_the_beginning_of_the_age(self):
        user = UserFactory()
        entries = [
            user,
            PlaylistHistoryFactory(user=user,
                                   track=TrackFactory(duration=1000)),
            PlaylistHistoryFactory(user=user,
                                   track=TrackFactory(duration=500)),
            PlaylistHistoryFactory(user=user,
                                   track=TrackFactory(duration=700)),
            PlaylistHistoryFactory(track=TrackFactory(duration=700)),
        ]
        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['total_play_time'] == 2200
예제 #11
0
    def should_returns_list_of_users_total_number_of_tracks_in_queue(self):
        tracks = TrackFactory.create_batch(3)
        users = UserFactory.create_batch(2)
        db.session.add_all(tracks + users)
        db.session.commit()

        users_in_queue = [users[0], users[0], users[1]]
        for track in tracks:
            self.redis.rpush(
                config.PLAYLIST_REDIS_KEY,
                json.dumps({
                    'uri': track.spotify_uri,
                    'user': users_in_queue.pop().id
                }))

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

        assert response.status_code == 200
        assert response.json['users'] == {users[0].id: 2, users[1].id: 1}
예제 #12
0
    def should_return_played_tracks_from_selected_date(self):
        user = UserFactory()
        most_played = TrackFactory()
        second_most_played = TrackFactory()
        entries = [
            user,
            PlaylistHistoryFactory(track=most_played, user=user),
            PlaylistHistoryFactory(track=most_played, user=user),
            PlaylistHistoryFactory(track=second_most_played, user=user),
            PlaylistHistoryFactory(track=second_most_played),
            PlaylistHistoryFactory(track=second_most_played,
                                   user=user,
                                   created=datetime.datetime(2014,
                                                             1,
                                                             1,
                                                             tzinfo=tzutc())),
            PlaylistHistoryFactory(
                created=datetime.datetime(2014, 1, 1, tzinfo=tzutc())),
        ]
        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, response.data
        assert response.json['most_played_tracks'] == [
            {
                'track': FMTrackSerializer().serialize(most_played),
                'total': 2
            },
            {
                'track': FMTrackSerializer().serialize(second_most_played),
                'total': 1
            },
        ]