Skip to content

Commit

Permalink
use specialized make_mocked_request method from test_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
nickolai-dr committed Jun 2, 2016
1 parent 1215f5d commit c41c34a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 52 deletions.
16 changes: 3 additions & 13 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
from collections.abc import Sized, Container, Iterable, Mapping, MutableMapping
from unittest import mock
from urllib.parse import unquote
from multidict import CIMultiDict
import aiohttp.web
from aiohttp import hdrs, helpers
from aiohttp.web import (UrlDispatcher, Request, Response,
from aiohttp.web import (UrlDispatcher, Response,
HTTPMethodNotAllowed, HTTPNotFound,
HTTPCreated)
from aiohttp.protocol import HttpVersion, RawRequestMessage
from aiohttp.web_urldispatcher import (_defaultExpectHandler,
DynamicRoute,
PlainRoute,
SystemRoute,
ResourceRoute,
AbstractResource,
View)
from aiohttp.test_utils import make_mocked_request


class TestUrlDispatcher(unittest.TestCase):
Expand All @@ -33,16 +32,7 @@ def tearDown(self):
self.loop.close()

def make_request(self, method, path):
self.app = mock.Mock()
message = RawRequestMessage(method, path, HttpVersion(1, 1),
CIMultiDict(), [], False, False)
self.payload = mock.Mock()
self.transport = mock.Mock()
self.reader = mock.Mock()
self.writer = mock.Mock()
req = Request(self.app, message, self.payload,
self.transport, self.reader, self.writer)
return req
return make_mocked_request(method, path)

def make_handler(self):

Expand Down
42 changes: 3 additions & 39 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
import pytest
from unittest import mock

from multidict import MultiDict, CIMultiDict
from aiohttp.signals import Signal
from aiohttp.web import Request
from aiohttp.protocol import HttpVersion
from aiohttp.protocol import RawRequestMessage
from aiohttp.test_utils import make_mocked_request


@pytest.fixture
def make_request():
def maker(method, path, headers=CIMultiDict(), *,
version=HttpVersion(1, 1), closing=False,
sslcontext=None,
secure_proxy_ssl_header=None):
if version < HttpVersion(1, 1):
closing = True
app = mock.Mock()
app._debug = False
app.on_response_prepare = Signal(app)
message = RawRequestMessage(method, path, version, headers,
[(k.encode('utf-8'), v.encode('utf-8'))
for k, v in headers.items()],
closing, False)
payload = mock.Mock()
transport = mock.Mock()

def get_extra_info(key):
if key == 'sslcontext':
return sslcontext
else:
return None

transport.get_extra_info.side_effect = get_extra_info
writer = mock.Mock()
reader = mock.Mock()
req = Request(app, message, payload,
transport, reader, writer,
secure_proxy_ssl_header=secure_proxy_ssl_header)

assert req.app is app
assert req.content is payload
assert req.transport is transport

return req
return maker
return make_mocked_request


def test_ctor(make_request, warning):
Expand Down

0 comments on commit c41c34a

Please sign in to comment.