From d4eabd3956c98194eb13d28b97c3f0f29c7af26e Mon Sep 17 00:00:00 2001
From: pnuckowski
Date: Wed, 11 Dec 2024 23:52:54 +0100
Subject: [PATCH 1/2] fix: added condition on py3.8 while supporting
ClientSession.base_url
---
aioresponses/core.py | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/aioresponses/core.py b/aioresponses/core.py
index 2aa8e05..48426b4 100644
--- a/aioresponses/core.py
+++ b/aioresponses/core.py
@@ -29,6 +29,7 @@
)
from aiohttp.helpers import TimerNoop
from multidict import CIMultiDict, CIMultiDictProxy
+from packaging.version import Version
from .compat import (
URL,
@@ -36,7 +37,7 @@
stream_reader_factory,
merge_params,
normalize_url,
- RequestInfo,
+ RequestInfo, AIOHTTP_VERSION,
)
@@ -500,13 +501,15 @@ async def _request_mock(self, orig_self: ClientSession,
if orig_self.closed:
raise RuntimeError('Session is closed')
- # Join url with ClientSession._base_url
- url = orig_self._build_url(url)
- url_origin = str(url)
-
- # Combine ClientSession headers with passed headers
- if orig_self.headers:
- kwargs["headers"] = orig_self._prepare_headers(kwargs.get("headers"))
+ if AIOHTTP_VERSION >= Version('3.8.0'):
+ # Join url with ClientSession._base_url
+ url = orig_self._build_url(url)
+ url_origin = str(url)
+ # Combine ClientSession headers with passed headers
+ if orig_self.headers:
+ kwargs["headers"] = orig_self._prepare_headers(kwargs.get("headers"))
+ else:
+ url_origin = url
url = normalize_url(merge_params(url, kwargs.get('params')))
url_str = str(url)
From e14c9d5215c5adf1e5125bdae6bf6dae26f81aba Mon Sep 17 00:00:00 2001
From: pnuckowski
Date: Thu, 12 Dec 2024 00:05:44 +0100
Subject: [PATCH 2/2] fix: flake8
---
aioresponses/core.py | 3 +--
requirements-dev.txt | 5 ++---
setup.cfg | 1 +
tests/test_aioresponses.py | 2 ++
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/aioresponses/core.py b/aioresponses/core.py
index 48426b4..566e678 100644
--- a/aioresponses/core.py
+++ b/aioresponses/core.py
@@ -40,7 +40,6 @@
RequestInfo, AIOHTTP_VERSION,
)
-
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
@@ -224,7 +223,7 @@ def __repr__(self) -> str:
class aioresponses(object):
"""Mock aiohttp requests made by ClientSession."""
_matches = None # type: Dict[str, RequestMatch]
- _responses = None # type: List[ClientResponse]
+ _responses: List[ClientResponse] = None
requests = None # type: Dict
def __init__(self, **kwargs: Any):
diff --git a/requirements-dev.txt b/requirements-dev.txt
index bb31c52..04cea66 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,6 +1,6 @@
pip
wheel
-flake8==3.8.3
+flake8==5.0.4
tox==3.19.0
coverage==5.2.1
Sphinx==1.5.6
@@ -10,5 +10,4 @@ pytest-html==2.1.1
ddt==1.4.1
typing
asynctest==0.13.0
-yarl==1.9.4
-setuptools==69.5.1
+yarl==1.9.4
\ No newline at end of file
diff --git a/setup.cfg b/setup.cfg
index 0b0fe1d..9db058d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -35,6 +35,7 @@ universal = 1
[flake8]
exclude = docs
+max-line-length = 120
[tool:pytest]
testpaths = tests
diff --git a/tests/test_aioresponses.py b/tests/test_aioresponses.py
index 23fce89..7b53b0b 100644
--- a/tests/test_aioresponses.py
+++ b/tests/test_aioresponses.py
@@ -86,6 +86,7 @@ async def test_returned_instance_and_status_code(self, m):
("http://example.com/", "/api?foo=bar#fragment")
)
@aioresponses()
+ @skipIf(condition=AIOHTTP_VERSION < Version('3.8.0'), reason='aiohttp must be >= 3.8.0')
async def test_base_url(self, base_url, relative_url, m):
m.get(self.url, status=200)
self.session = ClientSession(base_url=base_url)
@@ -93,6 +94,7 @@ async def test_base_url(self, base_url, relative_url, m):
self.assertEqual(response.status, 200)
@aioresponses()
+ @skipIf(condition=AIOHTTP_VERSION < Version('3.8.0'), reason='aiohttp must be >= 3.8.0')
async def test_session_headers(self, m):
m.get(self.url)
self.session = ClientSession(headers={"Authorization": "Bearer foobar"})