Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent saved requests to be modified #143

Merged
merged 1 commit into from Dec 16, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import asyncio
import json
import copy
from collections import namedtuple
from distutils.version import StrictVersion
from functools import wraps
@@ -334,7 +335,7 @@ def add(self, url: 'Union[URL, str, Pattern]', method: str = hdrs.METH_GET,

key = (method, url)
self.requests.setdefault(key, [])
self.requests[key].append(RequestCall(args, kwargs))
self.requests[key].append(RequestCall(args, copy.deepcopy(kwargs)))

if response is None:
raise ClientConnectionError(
@@ -231,23 +231,39 @@ def test_raising_custom_error(self):

@asyncio.coroutine
def test_multiple_requests(self):
"""Ensure that requests are saved the way they would have been sent."""
with aioresponses() as m:
m.get(self.url, status=200)
m.get(self.url, status=201)
m.get(self.url, status=202)
resp = yield from self.session.get(self.url)
json_content_as_ref = [1]
resp = yield from self.session.get(self.url, json=json_content_as_ref)
self.assertEqual(resp.status, 200)
resp = yield from self.session.get(self.url)
json_content_as_ref[:] = [2]
resp = yield from self.session.get(self.url, json=json_content_as_ref)
self.assertEqual(resp.status, 201)
resp = yield from self.session.get(self.url)
json_content_as_ref[:] = [3]
resp = yield from self.session.get(self.url, json=json_content_as_ref)
self.assertEqual(resp.status, 202)

key = ('GET', URL(self.url))
self.assertIn(key, m.requests)
self.assertEqual(len(m.requests[key]), 3)
self.assertEqual(m.requests[key][0].args, tuple())
self.assertEqual(m.requests[key][0].kwargs,
{'allow_redirects': True})

first_request = m.requests[key][0]
self.assertEqual(first_request.args, tuple())
self.assertEqual(first_request.kwargs,
{'allow_redirects': True, "json": [1]})

second_request = m.requests[key][1]
self.assertEqual(second_request.args, tuple())
self.assertEqual(second_request.kwargs,
{'allow_redirects': True, "json": [2]})

third_request = m.requests[key][2]
self.assertEqual(third_request.args, tuple())
self.assertEqual(third_request.kwargs,
{'allow_redirects': True, "json": [3]})

@asyncio.coroutine
def test_request_retrieval_in_case_no_response(self):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.