Skip to content

Commit

Permalink
Merge pull request #98 from decaz/feature/fix-aiohttp-client-response
Browse files Browse the repository at this point in the history
Fix building response with aiohttp==3.3.0
  • Loading branch information
pnuckowski authored Jun 6, 2018
2 parents 9af8a15 + fc8ed90 commit 8b594ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
22 changes: 17 additions & 5 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from .compat import URL, merge_url_params, stream_reader

VERSION = StrictVersion(aiohttp.__version__)


class UrlResponse(object):
resp = None
Expand Down Expand Up @@ -55,24 +57,34 @@ def build_response(self) -> Union[ClientResponse, Exception]:
if isinstance(self.exception, Exception):
return self.exception
kwargs = {}
if StrictVersion(aiohttp.__version__) >= StrictVersion('3.1.0'):
if VERSION >= StrictVersion('3.1.0'):
loop = Mock()
loop.get_debug = Mock()
loop.get_debug.return_value = True
kwargs['request_info'] = Mock()
kwargs['writer'] = Mock()
kwargs['continue100'] = None
kwargs['timer'] = TimerNoop()
kwargs['auto_decompress'] = True
if VERSION >= StrictVersion('3.3.0'):
pass
else:
kwargs['auto_decompress'] = True
kwargs['traces'] = []
kwargs['loop'] = loop
kwargs['session'] = None
self.resp = self.response_class(self.method, URL(self.url), **kwargs)
# we need to initialize headers manually
self.resp.headers = CIMultiDict({hdrs.CONTENT_TYPE: self.content_type})
headers = CIMultiDict({hdrs.CONTENT_TYPE: self.content_type})
if self.headers:
self.resp.headers.update(self.headers)
self.resp.raw_headers = self._build_raw_headers(self.resp.headers)
headers.update(self.headers)
raw_headers = self._build_raw_headers(headers)
if VERSION >= StrictVersion('3.3.0'):
# Reified attributes
self.resp._headers = headers
self.resp._raw_headers = raw_headers
else:
self.resp.headers = headers
self.resp.raw_headers = raw_headers
self.resp.status = self.status
self.resp.content = stream_reader()
self.resp.content.feed_data(self.body)
Expand Down
8 changes: 5 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
envlist =
flake8,
coverage,
py35-aiohttp{20,21,22,23,30,31}
py36-aiohttp{20,21,22,23,30,31}
py35-aiohttp{20,21,22,23,30,31,32,33}
py36-aiohttp{20,21,22,23,30,31,32,33}
skipsdist=True

[testenv:flake8]
Expand All @@ -26,7 +26,9 @@ deps =
aiohttp23: aiohttp>=2.3,<2.4
aiohttp30: aiohttp>=3.0,<3.1
aiohttp31: aiohttp>=3.1,<3.2
aiohttpmaster: https://github.com/KeepSafe/aiohttp/archive/master.tar.gz
aiohttp32: aiohttp>=3.2,<3.3
aiohttp33: aiohttp>=3.3,<3.4
aiohttpmaster: https://github.com/aio-libs/aiohttp/archive/master.tar.gz
-r{toxinidir}/requirements-dev.txt

basepython =
Expand Down

0 comments on commit 8b594ff

Please sign in to comment.