summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2022-09-29 11:47:49 -0500
committerJordan Cook <jordan.cook.git@proton.me>2022-09-29 12:05:13 -0500
commit5204d487fea1d0b89e9eecdbc4a38621d2d4dbe4 (patch)
tree5a7683e4cb01359a151742223c4d3a4301d75f50 /tests/integration
parent8af0552b3f1011b5c004d345da4d94e48a40e4fe (diff)
downloadrequests-cache-5204d487fea1d0b89e9eecdbc4a38621d2d4dbe4.tar.gz
Match whether ignored_parameters are present in a request (without matching content)
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/base_cache_test.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/tests/integration/base_cache_test.py b/tests/integration/base_cache_test.py
index 5d69ea8..546f6c5 100644
--- a/tests/integration/base_cache_test.py
+++ b/tests/integration/base_cache_test.py
@@ -313,7 +313,7 @@ class BaseCacheTest:
assert response.from_cache is False
response = session.request(method, url, headers={"Authorization": "<Secret Key>"})
assert response.from_cache is True
- assert response.request.headers.get('Authorization') is None
+ assert response.request.headers.get('Authorization') == 'REDACTED'
@pytest.mark.parametrize('method', HTTPBIN_METHODS)
def test_filter_request_query_parameters(self, method):
@@ -325,23 +325,25 @@ class BaseCacheTest:
assert response.from_cache is True
query = urlparse(response.request.url).query
query_dict = parse_qs(query)
- assert 'api_key' not in query_dict
+ assert query_dict['api_key'] == ['REDACTED']
@pytest.mark.parametrize('post_type', ['data', 'json'])
def test_filter_request_post_data(self, post_type):
method = 'POST'
url = httpbin(method.lower())
+ body = {"api_key": "<Secret Key>"}
+ headers = {}
+ if post_type == 'data':
+ body = json.dumps(body)
+ headers = {'Content-Type': 'application/json'}
session = self.init_session(ignored_parameters=['api_key'])
- response = session.request(method, url, **{post_type: {"api_key": "<Secret Key>"}})
- assert response.from_cache is False
- response = session.request(method, url, **{post_type: {"api_key": "<Secret Key>"}})
+
+ response = session.request(method, url, headers=headers, **{post_type: body})
+ response = session.request(method, url, headers=headers, **{post_type: body})
assert response.from_cache is True
- if post_type == 'data':
- body = parse_qs(response.request.body)
- assert "api_key" not in body
- elif post_type == 'json':
- body = json.loads(response.request.body)
- assert "api_key" not in body
+
+ parsed_body = json.loads(response.request.body)
+ assert parsed_body['api_key'] == 'REDACTED'
@pytest.mark.parametrize('executor_class', [ThreadPoolExecutor, ProcessPoolExecutor])
@pytest.mark.parametrize('iteration', range(N_ITERATIONS))