Skip to content

Commit

Permalink
Use proper protocol object instead of mocking (thanks to @decaz's #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Feb 12, 2018
1 parent c583131 commit ce9d779
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 12 additions & 1 deletion aioresponses/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from aiohttp import __version__ as aiohttp_version
from aiohttp import __version__ as aiohttp_version, StreamReader
from typing import Optional
from urllib.parse import urlsplit, urlencode, SplitResult, urlunsplit

Expand All @@ -15,6 +15,17 @@ class URL(str):
yarl_available = False


if int(aiohttp_version.split('.')[0]) >= 3:
from aiohttp.client_proto import ResponseHandler

def stream_reader():
protocol = ResponseHandler()
return StreamReader(protocol)
else:
def stream_reader():
return StreamReader()


__all__ = ['URL', 'merge_url_params']


Expand Down
8 changes: 4 additions & 4 deletions aioresponses/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import asyncio
import json
from typing import Dict, Tuple
from unittest.mock import Mock, patch
from unittest.mock import patch
from urllib.parse import urlparse, parse_qsl, urlencode

from aiohttp import (
hdrs, ClientResponse, ClientConnectionError, StreamReader, client
hdrs, ClientResponse, ClientConnectionError, client
)
from collections import namedtuple
from functools import wraps
from multidict import CIMultiDict

from .compat import URL, merge_url_params
from .compat import URL, merge_url_params, stream_reader


class UrlResponse(object):
Expand Down Expand Up @@ -61,7 +61,7 @@ def build_response(self) -> 'ClientResponse':
self.resp.headers.update(self.headers)
self.resp.raw_headers = self._build_raw_headers(self.resp.headers)
self.resp.status = self.status
self.resp.content = StreamReader(Mock(_reading_paused=False))
self.resp.content = stream_reader()
self.resp.content.feed_data(self.body)
self.resp.content.feed_eof()

Expand Down

0 comments on commit ce9d779

Please sign in to comment.