Example #1
0
    def should_return_total_played_time_of_all_tracks_in_queue(self):
        tracks = TrackFactory.create_batch(3) * 2  # add some duplicates
        db.session.add_all(tracks + TrackFactory.create_batch(2))
        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 sum(t.duration for t in tracks) == response.json['play_time']
Example #2
0
    def should_returns_total_number_of_trucks_in_queue(self):
        tracks = TrackFactory.create_batch(3)
        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['total'] == 3
Example #3
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}
Example #4
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']