Skip to content

Commit

Permalink
Drop support for aiohttp 3.2.x and older
Browse files Browse the repository at this point in the history
aiohttp 3.2.x and older don't work on Python 3.7 and because we now
require Python 3.7+, we can drop support for aiohttp 3.0, 3.1, and 3.2.
  • Loading branch information
marcinsulikowski committed Oct 19, 2022
1 parent 58de98d commit 1c7d946
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Installing
Supported versions
------------------
- Python 3.6+
- aiohttp>=3.0.0,<4.0.0
- aiohttp>=3.3.0,<4.0.0

Usage
--------
Expand Down
47 changes: 19 additions & 28 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
)
from aiohttp.helpers import TimerNoop
from multidict import CIMultiDict, CIMultiDictProxy
from pkg_resources import parse_version

from .compat import (
AIOHTTP_VERSION,
URL,
Pattern,
stream_reader_factory,
Expand Down Expand Up @@ -146,26 +144,22 @@ def _build_response(self, url: 'Union[URL, str]',
body = str.encode(body)
if request_headers is None:
request_headers = {}
loop = Mock()
loop.get_debug = Mock()
loop.get_debug.return_value = True
kwargs = {} # type: Dict[str, Any]
if AIOHTTP_VERSION >= parse_version('3.1.0'):
loop = Mock()
loop.get_debug = Mock()
loop.get_debug.return_value = True
kwargs['request_info'] = RequestInfo(
url=url,
method=method,
headers=CIMultiDictProxy(CIMultiDict(**request_headers)),
)
kwargs['writer'] = Mock()
kwargs['continue100'] = None
kwargs['timer'] = TimerNoop()
if AIOHTTP_VERSION < parse_version('3.3.0'):
kwargs['auto_decompress'] = True
kwargs['traces'] = []
kwargs['loop'] = loop
kwargs['session'] = None
else:
loop = None
kwargs['request_info'] = RequestInfo(
url=url,
method=method,
headers=CIMultiDictProxy(CIMultiDict(**request_headers)),
)
kwargs['writer'] = Mock()
kwargs['continue100'] = None
kwargs['timer'] = TimerNoop()
kwargs['traces'] = []
kwargs['loop'] = loop
kwargs['session'] = None

# We need to initialize headers manually
_headers = CIMultiDict({hdrs.CONTENT_TYPE: content_type})
if headers:
Expand All @@ -176,13 +170,10 @@ def _build_response(self, url: 'Union[URL, str]',
for hdr in _headers.getall(hdrs.SET_COOKIE, ()):
resp.cookies.load(hdr)

if AIOHTTP_VERSION >= parse_version('3.3.0'):
# Reified attributes
resp._headers = _headers
resp._raw_headers = raw_headers
else:
resp.headers = _headers
resp.raw_headers = raw_headers
# Reified attributes
resp._headers = _headers
resp._raw_headers = raw_headers

resp.status = status
resp.reason = reason
resp.content = stream_reader_factory(loop)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aiohttp>=3.0.0,<4.0.0
aiohttp>=3.3.0,<4.0.0
6 changes: 1 addition & 5 deletions tests/test_aioresponses.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ async def test_raising_exception(self):
callback=lambda *_, **__: callback_called.set())
with self.assertRaises(HttpProcessingError):
await self.session.get(url)

await callback_called.wait()

async def test_multiple_requests(self):
Expand Down Expand Up @@ -632,8 +632,6 @@ async def test_redirect_missing_location_header(self, rsps):
self.assertEqual(str(response.url), self.url)

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.1.0'),
reason='aiohttp<3.1.0 does not add request info on response')
async def test_request_info(self, rsps):
rsps.get(self.url, status=200)

Expand All @@ -644,8 +642,6 @@ async def test_request_info(self, rsps):
assert request_info.headers == {}

@aioresponses()
@skipIf(condition=AIOHTTP_VERSION < parse_version('3.1.0'),
reason='aiohttp<3.1.0 does not add request info on response')
async def test_request_info_with_original_request_headers(self, rsps):
headers = {"Authorization": "Bearer access-token"}
rsps.get(self.url, status=200)
Expand Down
3 changes: 0 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ setenv =
passenv = PYTEST_ADDOPTS

deps =
aiohttp30: aiohttp>=3.0,<3.1
aiohttp31: aiohttp>=3.1,<3.2
aiohttp32: aiohttp>=3.2,<3.3
aiohttp33: aiohttp>=3.3,<3.4
aiohttp34: aiohttp>=3.4,<3.5
aiohttp35: aiohttp>=3.5,<3.6
Expand Down

0 comments on commit 1c7d946

Please sign in to comment.