From 075c34c8f98d3690f7167d8f885bfbd3d74dd67a Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 22 Jun 2017 20:28:24 +0300 Subject: [PATCH] Adopt to multidict 3.0.0 (#2000) * Fix couple tests * Another test * Fix last tests * Pin multidict requirement to 3.0.0 * Fix tests * Make test stable --- aiohttp/client_reqrep.py | 2 +- requirements-ci.txt | 2 +- tests/test_client_session.py | 17 +++++++---------- tests/test_http_parser.py | 6 +++--- tests/test_multipart.py | 2 +- tests/test_web_request.py | 4 ++-- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index b1a9939aec7..ee810cf4564 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -161,7 +161,7 @@ def update_headers(self, headers): def update_auto_headers(self, skip_auto_headers): self.skip_auto_headers = CIMultiDict( - (hdr, None) for hdr in skip_auto_headers) + (hdr, None) for hdr in sorted(skip_auto_headers)) used_headers = self.headers.copy() used_headers.extend(self.skip_auto_headers) diff --git a/requirements-ci.txt b/requirements-ci.txt index e40e3143441..f7f27755934 100644 --- a/requirements-ci.txt +++ b/requirements-ci.txt @@ -8,7 +8,7 @@ cython==0.25.2 chardet==3.0.4 isort==4.2.15 tox==2.7.0 -multidict==2.1.6 +multidict==3.0.0 async-timeout==1.2.1 sphinxcontrib-asyncio==0.2.0 sphinxcontrib-newsfeed==0.1.4 diff --git a/tests/test_client_session.py b/tests/test_client_session.py index cd7b8adab6c..fc01f5198e4 100644 --- a/tests/test_client_session.py +++ b/tests/test_client_session.py @@ -67,7 +67,7 @@ def test_init_headers_simple_dict(create_session): session = create_session(headers={"h1": "header1", "h2": "header2"}) assert (sorted(session._default_headers.items()) == - ([("H1", "header1"), ("H2", "header2")])) + ([("h1", "header1"), ("h2", "header2")])) def test_init_headers_list_of_tuples(create_session): @@ -126,8 +126,7 @@ def test_merge_headers(create_session): headers = session._prepare_headers({"h1": "h1"}) assert isinstance(headers, CIMultiDict) - assert headers == CIMultiDict([("h2", "header2"), - ("h1", "h1")]) + assert headers == {"h1": "h1", "h2": "header2"} def test_merge_headers_with_multi_dict(create_session): @@ -135,8 +134,7 @@ def test_merge_headers_with_multi_dict(create_session): "h2": "header2"}) headers = session._prepare_headers(MultiDict([("h1", "h1")])) assert isinstance(headers, CIMultiDict) - assert headers == CIMultiDict([("h2", "header2"), - ("h1", "h1")]) + assert headers == {"h1": "h1", "h2": "header2"} def test_merge_headers_with_list_of_tuples(create_session): @@ -144,8 +142,7 @@ def test_merge_headers_with_list_of_tuples(create_session): "h2": "header2"}) headers = session._prepare_headers([("h1", "h1")]) assert isinstance(headers, CIMultiDict) - assert headers == CIMultiDict([("h2", "header2"), - ("h1", "h1")]) + assert headers == {"h1": "h1", "h2": "header2"} def test_merge_headers_with_list_of_tuples_duplicated_names(create_session): @@ -156,9 +153,9 @@ def test_merge_headers_with_list_of_tuples_duplicated_names(create_session): ("h1", "v2")]) assert isinstance(headers, CIMultiDict) - assert headers == CIMultiDict([("H2", "header2"), - ("H1", "v1"), - ("H1", "v2")]) + assert list(sorted(headers.items())) == [("h1", "v1"), + ("h1", "v2"), + ("h2", "header2")] def test_http_GET(session, params): diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index 4173765870c..3d677bde884 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -66,8 +66,8 @@ def test_parse_headers(parser): assert len(messages) == 1 msg = messages[0][0] - assert list(msg.headers.items()) == [('Test', 'line continue'), - ('Test2', 'data')] + assert list(msg.headers.items()) == [('test', 'line continue'), + ('test2', 'data')] assert msg.raw_headers == ((b'test', b'line continue'), (b'test2', b'data')) assert not msg.should_close @@ -134,7 +134,7 @@ def test_headers_multi_feed(parser): assert len(messages) == 1 msg = messages[0][0] - assert list(msg.headers.items()) == [('Test', 'line continue')] + assert list(msg.headers.items()) == [('test', 'line continue')] assert msg.raw_headers == ((b'test', b'line continue'),) assert not msg.should_close assert msg.compression is None diff --git a/tests/test_multipart.py b/tests/test_multipart.py index e3dd38ab909..d879adbe139 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -843,7 +843,7 @@ def test_writer_write(buf, stream, writer): b'--:\r\n' b'Content-Type: multipart/mixed; boundary="::"\r\n' - b'X-Custom: test\r\nContent-Length: 93\r\n\r\n' + b'X-CUSTOM: test\r\nContent-Length: 93\r\n\r\n' b'--::\r\n' b'Content-Type: text/plain; charset=utf-8\r\n' b'Content-Length: 14\r\n\r\n' diff --git a/tests/test_web_request.py b/tests/test_web_request.py index 440cfd71e59..36c16823cd0 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -49,7 +49,7 @@ def test_ctor(make_request): assert req.protocol is protocol assert req.transport is protocol.transport assert req.headers == headers - assert req.raw_headers == ((b'Foo', b'bar'),) + assert req.raw_headers == ((b'FOO', b'bar'),) assert req.task is req._task with pytest.warns(DeprecationWarning): @@ -361,7 +361,7 @@ def test_host_by_host_header(make_request): def test_raw_headers(make_request): req = make_request('GET', '/', headers=CIMultiDict({'X-HEADER': 'aaa'})) - assert req.raw_headers == ((b'X-Header', b'aaa'),) + assert req.raw_headers == ((b'X-HEADER', b'aaa'),) def test_rel_url(make_request):