-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
conftest.py
49 lines (39 loc) · 1.41 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
import pytest
from environs import Env
import deezer
env = Env()
env.read_env()
@pytest.fixture()
def client():
"""Create an unauthenticated client for tests."""
with deezer.Client(
# This is to get human-readable response output in VCR cassettes
headers={"Accept-Encoding": "identity"},
) as client:
yield client
@pytest.fixture()
def client_token():
"""Create an authenticated client for tests."""
with deezer.Client(
access_token=env("API_TOKEN", "dummy"),
headers={"Accept-Encoding": "identity"},
) as client:
yield client
@pytest.fixture(scope="module", autouse=True)
def vcr_config():
"""Clean up some headers from cassettes."""
return {
"filter_query_parameters": [("access_token", "dummy")],
"before_record_response": _clean_response,
}
def _clean_response(response):
"""Remove some info from the response before writing cassettes."""
remove_headers = {"Set-Cookie", "Date", "P3P"}
if isinstance(response["headers"], dict):
# Normal client stores headers as dict
for header_name in remove_headers:
response["headers"].pop(header_name, None)
elif isinstance(response["headers"], list):
# Tornado client stores headers as a list of 2-tuples
response["headers"] = [(name, value) for name, value in response["headers"] if name not in remove_headers]
return response