-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Random resouce added to generate and add random tracks into queue
- Loading branch information
Showing
5 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
|
||
""" | ||
tests.views.player.test_random | ||
=============================== | ||
Unit tests for the ``fm.views.player.RandomView`` class. | ||
""" | ||
|
||
import httplib | ||
import json | ||
|
||
import pytest | ||
from flask import url_for | ||
from fm.ext import db | ||
from tests.factories.spotify import TrackFactory | ||
from tests.factories.user import UserFactory | ||
|
||
|
||
@pytest.mark.usefixtures("authenticated") | ||
class TestRandom(object): | ||
|
||
@pytest.mark.usefixtures("unauthenticated") | ||
def hit_random_endpoint_as_unauthorized_user(self): | ||
response = self.client.post(url_for('player.random')) | ||
assert response.status_code == httplib.FORBIDDEN | ||
|
||
def data_without_number_of_tracks(self): | ||
response = self.client.post(url_for('player.random')) | ||
assert response.status_code == httplib.BAD_REQUEST | ||
|
||
def add_some_tracks_into_queue(self): | ||
tracks = [TrackFactory(), TrackFactory(), TrackFactory()] | ||
users = [UserFactory(), UserFactory(), UserFactory()] | ||
|
||
db.session.add_all(tracks + users) | ||
db.session.commit() | ||
|
||
response = self.client.post( | ||
url_for('player.random'), | ||
data=json.dumps({'tracks': 2}) | ||
) | ||
|
||
assert response.status_code == httplib.CREATED |