-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsettings.py
More file actions
59 lines (49 loc) · 1.71 KB
/
settings.py
File metadata and controls
59 lines (49 loc) · 1.71 KB
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
56
57
58
59
"""Defines all test wide settings and variables"""
import os
import json
from vcr import VCR
from yarl import URL
from domaintools import API, utils
def remove_server(response):
response.get("headers", {}).pop("server", None)
response.get("headers", {}).pop("Server", None)
if "url" in response:
url = URL(response["url"])
query = dict(url.query)
if "api_username" in query:
query.update(api_username="test")
if "api_key" in query:
query.update(api_key="test")
if "signature" in query:
query.update(signature="test")
response["url"] = str(url.with_query(query))
return response
def filter_patch_parameters(request):
if request.method == "PATCH" and request.body:
body = json.loads(request.body)
body.pop("api_username", None)
body.pop("api_key", None)
body.pop("signature", None)
body.pop("timestamp", None)
request.body = json.dumps(body).encode("utf-8")
return request
vcr = VCR(
before_record_response=remove_server,
before_record_request=filter_patch_parameters,
filter_query_parameters=["timestamp", "signature", "api_username", "api_key"],
filter_post_data_parameters=["timestamp", "signature", "api_username", "api_key"],
filter_headers=["x-api-key"],
cassette_library_dir="tests/fixtures/vcr/",
path_transformer=VCR.ensure_suffix(".yaml"),
record_mode="new_episodes",
)
with vcr.use_cassette("init_user_account"):
api = API(
os.getenv("TEST_USER", "test"),
os.getenv("TEST_KEY", "test"),
)
feeds_api = API(
os.getenv("TEST_USER", "test"),
os.getenv("TEST_KEY", "test"),
rate_limit=False,
)