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

Adapt istr #1015

Merged
merged 14 commits into from
Jul 29, 2016
Prev Previous commit
Next Next commit
Fix protocol tests
  • Loading branch information
asvetlov committed Jul 29, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0c9046cf3a4827d4bc6dcbe0013cf35d8483c7ab
2 changes: 1 addition & 1 deletion aiohttp/protocol.py
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ def parse_headers(self, lines):

bvalue = bvalue.strip()

name = bname.decode('utf-8', 'surrogateescape')
name = istr(bname.decode('utf-8', 'surrogateescape'))
value = bvalue.decode('utf-8', 'surrogateescape')

# keep-alive and encoding
30 changes: 12 additions & 18 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
@@ -90,15 +90,15 @@ def test_add_header(transport):
assert [] == list(msg.headers)

msg.add_header('content-type', 'plain/html')
assert [('CONTENT-TYPE', 'plain/html')] == list(msg.headers.items())
assert [('Content-Type', 'plain/html')] == list(msg.headers.items())


def test_add_header_with_spaces(transport):
msg = protocol.Response(transport, 200)
assert [] == list(msg.headers)

msg.add_header('content-type', ' plain/html ')
assert [('CONTENT-TYPE', 'plain/html')] == list(msg.headers.items())
assert [('Content-Type', 'plain/html')] == list(msg.headers.items())


def test_add_header_non_ascii(transport):
@@ -125,7 +125,7 @@ def test_add_headers(transport):
assert [] == list(msg.headers)

msg.add_headers(('content-type', 'plain/html'))
assert [('CONTENT-TYPE', 'plain/html')] == list(msg.headers.items())
assert [('Content-Type', 'plain/html')] == list(msg.headers.items())


def test_add_headers_length(transport):
@@ -151,7 +151,7 @@ def test_add_headers_upgrade_websocket(transport):
assert [] == list(msg.headers)

msg.add_headers(('upgrade', 'websocket'))
assert [('UPGRADE', 'websocket')] == list(msg.headers.items())
assert [('Upgrade', 'websocket')] == list(msg.headers.items())


def test_add_headers_connection_keepalive(transport):
@@ -201,33 +201,29 @@ def test_default_headers_chunked(transport):
msg = protocol.Response(transport, 200)
msg._add_default_headers()

headers = [r for r, _ in msg.headers.items()]
assert 'TRANSFER-ENCODING' not in headers
assert 'TRANSFER-ENCODING' not in msg.headers

msg = protocol.Response(transport, 200)
msg.enable_chunked_encoding()
msg.send_headers()

headers = [r for r, _ in msg.headers.items()]
assert 'TRANSFER-ENCODING' in headers
assert 'TRANSFER-ENCODING' in msg.headers


def test_default_headers_connection_upgrade(transport):
msg = protocol.Response(transport, 200)
msg.upgrade = True
msg._add_default_headers()

headers = [r for r in msg.headers.items() if r[0] == 'CONNECTION']
assert [('CONNECTION', 'upgrade')] == headers
assert msg.headers['Connection'] == 'upgrade'


def test_default_headers_connection_close(transport):
msg = protocol.Response(transport, 200)
msg.force_close()
msg._add_default_headers()

headers = [r for r in msg.headers.items() if r[0] == 'CONNECTION']
assert [('CONNECTION', 'close')] == headers
assert msg.headers['Connection'] == 'close'


def test_default_headers_connection_keep_alive_http_10(transport):
@@ -236,8 +232,7 @@ def test_default_headers_connection_keep_alive_http_10(transport):
msg.keepalive = True
msg._add_default_headers()

headers = [r for r in msg.headers.items() if r[0] == 'CONNECTION']
assert [('CONNECTION', 'keep-alive')] == headers
assert msg.headers['Connection'] == 'keep-alive'


def test_default_headers_connection_keep_alive_11(transport):
@@ -246,8 +241,7 @@ def test_default_headers_connection_keep_alive_11(transport):
msg.keepalive = True
msg._add_default_headers()

headers = [r for r in msg.headers.items() if r[0] == 'CONNECTION']
assert 'CONNECTION' not in headers
assert 'Connection' not in msg.headers


def test_send_headers(transport):
@@ -262,7 +256,7 @@ def test_send_headers(transport):
content = b''.join([arg[1][0] for arg in list(write.mock_calls)])

assert content.startswith(b'HTTP/1.1 200 OK\r\n')
assert b'CONTENT-TYPE: plain/html' in content
assert b'Content-Type: plain/html' in content
assert msg.headers_sent
assert msg.is_headers_sent()
# cleanup
@@ -281,7 +275,7 @@ def test_send_headers_non_ascii(transport):
content = b''.join([arg[1][0] for arg in list(write.mock_calls)])

assert content.startswith(b'HTTP/1.1 200 OK\r\n')
assert b'X-HEADER: \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82' in content
assert b'X-Header: \xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82' in content
assert msg.headers_sent
assert msg.is_headers_sent()
# cleanup