Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid use mutable CIMultiDict kw param in make_mocked_request #997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ Yury Selivanov
Yusuke Tsutsumi
Марк Коренберг
Семён Марьясин
Pau Freixes
17 changes: 12 additions & 5 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def get_extra_info(key):
_not_set = object()


def make_mocked_request(method, path, headers=CIMultiDict(), *,
def make_mocked_request(method, path, headers=None, *,
version=HttpVersion(1, 1), closing=False,
app=None,
reader=_not_set,
Expand Down Expand Up @@ -616,10 +616,17 @@ def make_mocked_request(method, path, headers=CIMultiDict(), *,

if version < HttpVersion(1, 1):
closing = True
message = RawRequestMessage(method, path, version, headers,
[(k.encode('utf-8'), v.encode('utf-8'))
for k, v in headers.items()],
closing, False)

if headers:
hdrs = headers
raw_hdrs = [
(k.encode('utf-8'), v.encode('utf-8')) for k, v in headers.items()]
else:
hdrs = CIMultiDict()
raw_hdrs = []

message = RawRequestMessage(method, path, version, hdrs,
raw_hdrs, closing, False)
if app is None:
app = _create_app_mock()

Expand Down
10 changes: 8 additions & 2 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def test_ctor(make_request, warning):
assert '/path/to?a=1&b=2' == req.path_qs
assert '/path/to' == req.path
assert 'a=1&b=2' == req.query_string
assert CIMultiDict() == req.headers
assert () == req.raw_headers

get = req.GET
assert MultiDict([('a', '1'), ('b', '2')]) == get
Expand All @@ -29,18 +31,22 @@ def test_ctor(make_request, warning):
assert req.keep_alive

# just make sure that all lines of make_mocked_request covered
headers = CIMultiDict(FOO='bar')
reader = mock.Mock()
writer = mock.Mock()
payload = mock.Mock()
transport = mock.Mock()
app = mock.Mock()
req = make_request('GET', '/path/to?a=1&b=2', writer=writer, reader=reader,
payload=payload, transport=transport, app=app)
req = make_request('GET', '/path/to?a=1&b=2', headers=headers,
writer=writer, reader=reader, payload=payload,
transport=transport, app=app)
assert req.app is app
assert req.content is payload
assert req.transport is transport
assert req._reader is reader
assert req._writer is writer
assert req.headers == headers
assert req.raw_headers == ((b'FOO', b'bar'),)


def test_doubleslashes(make_request):
Expand Down