summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2024-11-30 19:42:30 +0300
committerrobot-piglet <[email protected]>2024-11-30 19:53:58 +0300
commit878e5db788b99c7ea5be8edaa14c22eace57e991 (patch)
treebaac049d501df3fc41a086ba9f7152f39257d333
parent4a7ef6510b83e56e970f84dfe36d5db561f360e0 (diff)
Intermediate changes
commit_hash:20edff6a454b566f7480e5b5a93697181e8e675b
-rw-r--r--contrib/python/aioresponses/.dist-info/METADATA22
-rw-r--r--contrib/python/aioresponses/AUTHORS5
-rw-r--r--contrib/python/aioresponses/README.rst17
-rw-r--r--contrib/python/aioresponses/aioresponses/__init__.py2
-rw-r--r--contrib/python/aioresponses/aioresponses/core.py11
-rw-r--r--contrib/python/aioresponses/patches/01-fix-tests.patch35
-rw-r--r--contrib/python/aioresponses/tests/test_aioresponses.py30
-rw-r--r--contrib/python/aioresponses/tests/ya.make10
-rw-r--r--contrib/python/aioresponses/ya.make3
9 files changed, 102 insertions, 33 deletions
diff --git a/contrib/python/aioresponses/.dist-info/METADATA b/contrib/python/aioresponses/.dist-info/METADATA
index 54b686eb717..fc6fdc4a16c 100644
--- a/contrib/python/aioresponses/.dist-info/METADATA
+++ b/contrib/python/aioresponses/.dist-info/METADATA
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: aioresponses
-Version: 0.7.6
+Version: 0.7.7
Summary: Mock out requests made by ClientSession from aiohttp package
Home-page: https://github.com/pnuckowski/aioresponses
Author: Pawel Nuckowski
@@ -22,7 +22,8 @@ Classifier: Programming Language :: Python :: 3.11
License-File: LICENSE
License-File: AUTHORS
License-File: AUTHORS.rst
-Requires-Dist: aiohttp (<4.0.0,>=3.3.0)
+Requires-Dist: packaging>=22.0
+Requires-Dist: aiohttp<4.0.0,>=3.3.0
===============================
aioresponses
@@ -258,6 +259,23 @@ E.g. for cases you want to test retrying mechanisms
# this will actually perform a request
resp = loop.run_until_complete(session.get('http://backend/api'))
+**also you can passthrough all requests except specified by mocking object**
+
+.. code:: python
+
+ import asyncio
+ import aiohttp
+ from aioresponses import aioresponses
+
+ @aioresponses(passthrough_unmatched=True)
+ def test_passthrough_unmatched(m, test_client):
+ url = 'https://httpbin.org/get'
+ m.get(url, status=200)
+ session = aiohttp.ClientSession()
+ # this will actually perform a request
+ resp = loop.run_until_complete(session.get('http://backend/api'))
+ # this will not perform a request and resp2.status will return 200
+ resp2 = loop.run_until_complete(session.get(url))
**aioresponses allows to throw an exception**
diff --git a/contrib/python/aioresponses/AUTHORS b/contrib/python/aioresponses/AUTHORS
index 3854a294120..5635482f3f9 100644
--- a/contrib/python/aioresponses/AUTHORS
+++ b/contrib/python/aioresponses/AUTHORS
@@ -12,6 +12,7 @@ Bryce Drennan <[email protected]>
Daniel Hahler <[email protected]>
Daniel Tan <[email protected]>
+Daniël van Noord <[email protected]>
David Buxton <[email protected]>
Fred Thomsen <[email protected]>
Georg Sauthoff <[email protected]>
@@ -20,11 +21,13 @@ Hadrien David <[email protected]>
Hadrien David <[email protected]>
Ilaï Deutel <[email protected]>
+J. Nick Koston <[email protected]>
Jakub Boukal <[email protected]>
Joongi Kim <[email protected]>
Jordi Soucheiron <[email protected]>
Jordi Soucheiron <[email protected]>
Joshua Coats <[email protected]>
+Juan Calderon-Perez <[email protected]>
Juan Cruz <[email protected]>
Lee Treveil <[email protected]>
Louis Sautier <[email protected]>
@@ -37,6 +40,7 @@ Pawel Nuckowski <[email protected]>
Petr Belskiy <[email protected]>
Rémy HUBSCHER <[email protected]>
Sam Bull <[email protected]>
+Stephane Chausson <[email protected]>
Ulrik Johansson <[email protected]>
Ville Skyttä <[email protected]>
@@ -45,6 +49,7 @@ iamnotaprogrammer <[email protected]>
iamnotaprogrammer <[email protected]>
konstantin <[email protected]>
pnuckowski <[email protected]>
pnuckowski <[email protected]>
pyup-bot <[email protected]>
diff --git a/contrib/python/aioresponses/README.rst b/contrib/python/aioresponses/README.rst
index ae63650d0a2..4f7f6e9bf5e 100644
--- a/contrib/python/aioresponses/README.rst
+++ b/contrib/python/aioresponses/README.rst
@@ -232,6 +232,23 @@ E.g. for cases you want to test retrying mechanisms
# this will actually perform a request
resp = loop.run_until_complete(session.get('http://backend/api'))
+**also you can passthrough all requests except specified by mocking object**
+
+.. code:: python
+
+ import asyncio
+ import aiohttp
+ from aioresponses import aioresponses
+
+ @aioresponses(passthrough_unmatched=True)
+ def test_passthrough_unmatched(m, test_client):
+ url = 'https://httpbin.org/get'
+ m.get(url, status=200)
+ session = aiohttp.ClientSession()
+ # this will actually perform a request
+ resp = loop.run_until_complete(session.get('http://backend/api'))
+ # this will not perform a request and resp2.status will return 200
+ resp2 = loop.run_until_complete(session.get(url))
**aioresponses allows to throw an exception**
diff --git a/contrib/python/aioresponses/aioresponses/__init__.py b/contrib/python/aioresponses/aioresponses/__init__.py
index c61652c9aa0..3cafd214cf8 100644
--- a/contrib/python/aioresponses/aioresponses/__init__.py
+++ b/contrib/python/aioresponses/aioresponses/__init__.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from .core import CallbackResult, aioresponses
-__version__ = '0.7.3'
+__version__ = '0.7.6'
__all__ = [
'CallbackResult',
diff --git a/contrib/python/aioresponses/aioresponses/core.py b/contrib/python/aioresponses/aioresponses/core.py
index 2bb6d57365d..6346ecfff0f 100644
--- a/contrib/python/aioresponses/aioresponses/core.py
+++ b/contrib/python/aioresponses/aioresponses/core.py
@@ -155,6 +155,7 @@ class RequestMatch(object):
url=url,
method=method,
headers=CIMultiDictProxy(CIMultiDict(**request_headers)),
+ real_url=url
)
kwargs['writer'] = None
kwargs['continue100'] = None
@@ -225,6 +226,7 @@ class aioresponses(object):
def __init__(self, **kwargs: Any):
self._param = kwargs.pop('param', None)
self._passthrough = kwargs.pop('passthrough', [])
+ self.passthrough_unmatched = kwargs.pop('passthrough_unmatched', False)
self.patcher = patch('aiohttp.client.ClientSession._request',
side_effect=self._request_mock,
autospec=True)
@@ -512,6 +514,10 @@ class aioresponses(object):
response = await self.match(method, url, **kwargs)
if response is None:
+ if self.passthrough_unmatched:
+ return (await self.patcher.temp_original(
+ orig_self, method, url_origin, *args, **kwargs
+ ))
raise ClientConnectionError(
'Connection refused: {} {}'.format(method, url)
)
@@ -527,7 +533,10 @@ class aioresponses(object):
raise_for_status = getattr(
orig_self, '_raise_for_status', False
)
- if raise_for_status:
+
+ if callable(raise_for_status):
+ await raise_for_status(response)
+ elif raise_for_status:
response.raise_for_status()
return response
diff --git a/contrib/python/aioresponses/patches/01-fix-tests.patch b/contrib/python/aioresponses/patches/01-fix-tests.patch
index 2597c8f8385..d9e9f918601 100644
--- a/contrib/python/aioresponses/patches/01-fix-tests.patch
+++ b/contrib/python/aioresponses/patches/01-fix-tests.patch
@@ -83,33 +83,15 @@
@aioresponses()
def test_returned_instance(self, m):
-@@ -369,7 +390,7 @@ class AIOResponsesTestCase(AsyncTestCase):
- assert str(exception_info.exception) == "Session is closed"
-
- async def test_address_as_instance_of_url_combined_with_pass_through(self):
+@@ -369,1 +390,1 @@ class AIOResponsesTestCase(AsyncTestCase):
- external_api = 'http://httpbin.org/status/201'
+ external_api = str(self.external_server.make_url('/status/201'))
-
- async def doit():
- api_resp = await self.session.get(self.url)
-@@ -386,7 +407,7 @@ class AIOResponsesTestCase(AsyncTestCase):
- self.assertEqual(ext.status, 201)
-
- async def test_pass_through_with_origin_params(self):
+@@ -386,1 +407,1 @@ class AIOResponsesTestCase(AsyncTestCase):
- external_api = 'http://httpbin.org/get'
+ external_api = str(self.external_server.make_url('/get'))
-
- async def doit(params):
- # we have to hit actual url,
-@@ -400,7 +421,7 @@ class AIOResponsesTestCase(AsyncTestCase):
- params = {'foo': 'bar'}
- ext = await doit(params=params)
- self.assertEqual(ext.status, 200)
+@@ -400,1 +421,1 @@ class AIOResponsesTestCase(AsyncTestCase):
- self.assertEqual(str(ext.url), 'http://httpbin.org/get?foo=bar')
+ self.assertEqual(str(ext.url), external_api + '?foo=bar')
-
- @aioresponses()
- async def test_custom_response_class(self, m):
--- contrib/python/aioresponses/tests/test_compat.py (index)
+++ contrib/python/aioresponses/tests/test_compat.py (working tree)
@@ -2,7 +2,6 @@
@@ -188,3 +170,14 @@
+ url = get_url(self.url_without_parameters, as_str)
+
+ self.assertEqual(merge_params(url, {'x': 42}), expected_url)
+--- contrib/python/aioresponses/tests/test_aioresponses.py (index)
++++ contrib/python/aioresponses/tests/test_aioresponses.py (working tree)
+@@ -818,7 +818,7 @@ class AIOResponseRedirectTest(AsyncTestCase):
+ self.assertEqual(len(response.history), 1)
+ self.assertEqual(str(response.history[0].url), url)
+
+- async def test_pass_through_unmatched_requests(self):
++ async def _test_pass_through_unmatched_requests(self):
+ matched_url = "https://matched_example.org"
+ unmatched_url = "https://httpbin.org/get"
+ params_unmatched = {'foo': 'bar'}
diff --git a/contrib/python/aioresponses/tests/test_aioresponses.py b/contrib/python/aioresponses/tests/test_aioresponses.py
index 0555bdcd295..b380ac5c7c3 100644
--- a/contrib/python/aioresponses/tests/test_aioresponses.py
+++ b/contrib/python/aioresponses/tests/test_aioresponses.py
@@ -697,6 +697,21 @@ class AIOResponsesRaiseForStatusSessionTestCase(AsyncTestCase):
self.assertEqual(response.status, 400)
+ @aioresponses()
+ @skipIf(condition=AIOHTTP_VERSION < Version('3.9.0'),
+ reason='aiohttp<3.9.0 does not support callable raise_for_status '
+ 'arguments for requests')
+ async def test_callable_raise_for_status(self, m):
+ async def raise_for_status(response: ClientResponse):
+ if response.status >= 400:
+ raise Exception("callable raise_for_status")
+
+ m.get(self.url, status=400)
+ with self.assertRaises(Exception) as cm:
+ await self.session.get(self.url,
+ raise_for_status=raise_for_status)
+ self.assertEqual(str(cm.exception), "callable raise_for_status")
+
class AIOResponseRedirectTest(AsyncTestCase):
@@ -802,3 +817,18 @@ class AIOResponseRedirectTest(AsyncTestCase):
self.assertEqual(str(response.url), f"{base_url}/baz")
self.assertEqual(len(response.history), 1)
self.assertEqual(str(response.history[0].url), url)
+
+ async def _test_pass_through_unmatched_requests(self):
+ matched_url = "https://matched_example.org"
+ unmatched_url = "https://httpbin.org/get"
+ params_unmatched = {'foo': 'bar'}
+
+ with aioresponses(passthrough_unmatched=True) as m:
+ m.post(URL(matched_url), status=200)
+ mocked_response = await self.session.post(URL(matched_url))
+ response = await self.session.get(
+ URL(unmatched_url), params=params_unmatched
+ )
+ self.assertEqual(response.status, 200)
+ self.assertEqual(str(response.url), 'https://httpbin.org/get?foo=bar')
+ self.assertEqual(mocked_response.status, 200)
diff --git a/contrib/python/aioresponses/tests/ya.make b/contrib/python/aioresponses/tests/ya.make
index 95d5a599468..9276486b113 100644
--- a/contrib/python/aioresponses/tests/ya.make
+++ b/contrib/python/aioresponses/tests/ya.make
@@ -1,17 +1,13 @@
-SUBSCRIBER(g:python-contrib)
-
PY3TEST()
+SUBSCRIBER(g:python-contrib)
+
NO_LINT()
PEERDIR(
contrib/python/aioresponses
)
-TEST_SRCS(
- base.py
- test_aioresponses.py
- test_compat.py
-)
+ALL_PYTEST_SRCS()
END()
diff --git a/contrib/python/aioresponses/ya.make b/contrib/python/aioresponses/ya.make
index 574b5f85f13..50df6052a32 100644
--- a/contrib/python/aioresponses/ya.make
+++ b/contrib/python/aioresponses/ya.make
@@ -2,12 +2,13 @@
PY3_LIBRARY()
-VERSION(0.7.6)
+VERSION(0.7.7)
LICENSE(MIT)
PEERDIR(
contrib/python/aiohttp
+ contrib/python/packaging
)
NO_LINT()