forked from browniebroke/deezer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
48 lines (38 loc) · 1.25 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
import pytest
from environs import Env
import deezer
env = Env()
env.read_env()
@pytest.fixture()
def client():
return deezer.Client( # nosec
app_id="foo",
app_secret="bar",
# This is to get human-readable response output in VCR cassettes
headers={"Accept-Encoding": "identity"},
)
@pytest.fixture()
def client_token(client):
client.access_token = env("API_TOKEN", "dummy")
return client
@pytest.fixture(scope="module", autouse=True)
def vcr_config():
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