Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def doit():
api_resp = yield from self.session.get(self.url)
# we have to hit actual url,
# otherwise we do not test pass through option properly
ext_rep = yield from self.session.get(URL(external_api))
return api_resp, ext_rep
"""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)
json_content_as_ref = [1]
resp = yield from self.session.get(self.url, json=json_content_as_ref)
self.assertEqual(resp.status, 200)
json_content_as_ref[:] = [2]
resp = yield from self.session.get(self.url, json=json_content_as_ref)
self.assertEqual(resp.status, 201)
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)
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,
def test_request_retrieval_in_case_no_response(self):
with aioresponses() as m:
with self.assertRaises(ClientConnectionError):
yield from self.session.get(self.url)
key = ('GET', URL(self.url))
self.assertIn(key, m.requests)
self.assertEqual(len(m.requests[key]), 1)
self.assertEqual(m.requests[key][0].args, tuple())
self.assertEqual(m.requests[key][0].kwargs,
{'allow_redirects': True})