-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
55 lines (43 loc) · 1.77 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
import runMe
import config
@pytest.fixture
def app():
app = runMe.app
return app
def test_hello(app):
"""Test the hello world route"""
response = app.test_client().get("/")
assert response.status_code == 200
assert "Hello, World!" in response.text
def test_get_access_token(app):
"""Test the get_access_token function"""
response = app.test_client().get("/spotify/token")
assert response.status_code == 200
assert response.json.get("access_token") is not None
def test_get_playlist(app):
"""Test the get_playlist function"""
response = app.test_client().get("/spotify/playlist")
assert response.status_code == 200
key_list_to_check = set(["artists", "name"])
assert (
set( # 0. convert dict_keys to set, as order doesn't matter
list(response.json.items())[0][ # 1. get list of tuples
1
].keys() # 2. get the second element of the tuple (the value) and get the keys
)
== key_list_to_check
)
def test_get_playlist_with_features(app):
"""Test the get_playlist function with features"""
response = app.test_client().get("/spotify/playlist?features=true")
assert response.status_code == 200
key_list_to_check = set(["artists", "name", "features"])
assert set(list(response.json.items())[0][1].keys()) == key_list_to_check
def test_get_playlist_with_features_and_output_list(app):
"""Test the get_playlist function with features and output list"""
response = app.test_client().get("/spotify/playlist?features=true&output=list")
assert response.status_code == 200
assert isinstance(response.json, list)
key_list_to_check = set(["artists", "name", "id", "features"])
assert set(response.json[0].keys()) == key_list_to_check