Skip to content

Commit

Permalink
Merge 9cdd40f into d73c265
Browse files Browse the repository at this point in the history
  • Loading branch information
allisson committed Mar 21, 2018
2 parents d73c265 + 9cdd40f commit a9b70ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,8 @@ matrix:
env: TOXENV=py35-aiohttp23
- python: 3.5
env: TOXENV=py35-aiohttp30
- python: 3.5
env: TOXENV=py35-aiohttp31

- python: 3.6
env: TOXENV=py36-aiohttp20
Expand All @@ -26,6 +28,8 @@ matrix:
env: TOXENV=py36-aiohttp23
- python: 3.6
env: TOXENV=py36-aiohttp30
- python: 3.6
env: TOXENV=py36-aiohttp31
# - python: 3.6
# env: TOXENV=py36-aiohttpmaster
#
Expand Down
31 changes: 22 additions & 9 deletions aioresponses/core.py
@@ -1,16 +1,16 @@
# -*- coding: utf-8 -*-

import asyncio
import json
from typing import Dict, Tuple, Union
from unittest.mock import patch
from urllib.parse import urlparse, parse_qsl, urlencode

from aiohttp import (
hdrs, ClientResponse, ClientConnectionError, client
)
from collections import namedtuple
from distutils.version import StrictVersion
from functools import wraps
from typing import Dict, Tuple, Union
from unittest.mock import Mock, patch
from urllib.parse import parse_qsl, urlencode, urlparse

import aiohttp
from aiohttp import ClientConnectionError, ClientResponse, client, hdrs
from aiohttp.helpers import TimerNoop
from multidict import CIMultiDict

from .compat import URL, merge_url_params, stream_reader
Expand Down Expand Up @@ -54,7 +54,20 @@ def match(self, method: str, url: str) -> bool:
def build_response(self) -> Union[ClientResponse, Exception]:
if isinstance(self.exception, Exception):
return self.exception
self.resp = self.response_class(self.method, URL(self.url))
kwargs = {}
if StrictVersion(aiohttp.__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
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})
if self.headers:
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Expand Up @@ -2,8 +2,8 @@
envlist =
flake8,
coverage,
py35-aiohttp{20,21,22,23,30}
py36-aiohttp{20,21,22,23,30}
py35-aiohttp{20,21,22,23,30,31}
py36-aiohttp{20,21,22,23,30,31}
skipsdist=True

[testenv:flake8]
Expand All @@ -22,6 +22,7 @@ deps =
aiohttp22: aiohttp>=2.2,<2.3
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
-r{toxinidir}/requirements-dev.txt

Expand Down

0 comments on commit a9b70ba

Please sign in to comment.