2018-11-11 16:57:57 +00:00
|
|
|
from sanic import helpers
|
2018-11-07 20:29:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_has_message_body():
|
|
|
|
tests = (
|
|
|
|
(100, False),
|
|
|
|
(102, False),
|
|
|
|
(204, False),
|
|
|
|
(200, True),
|
|
|
|
(304, False),
|
|
|
|
(400, True),
|
|
|
|
)
|
|
|
|
for status_code, expected in tests:
|
2018-11-11 16:57:57 +00:00
|
|
|
assert helpers.has_message_body(status_code) is expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_entity_header():
|
|
|
|
tests = (
|
|
|
|
("allow", True),
|
|
|
|
("extension-header", True),
|
|
|
|
("", False),
|
|
|
|
("test", False),
|
|
|
|
)
|
|
|
|
for header, expected in tests:
|
|
|
|
assert helpers.is_entity_header(header) is expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_hop_by_hop_header():
|
|
|
|
tests = (
|
|
|
|
("connection", True),
|
|
|
|
("upgrade", True),
|
|
|
|
("", False),
|
|
|
|
("test", False),
|
|
|
|
)
|
|
|
|
for header, expected in tests:
|
|
|
|
assert helpers.is_hop_by_hop_header(header) is expected
|
2018-11-19 15:30:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_remove_entity_headers():
|
|
|
|
tests = (
|
|
|
|
(
|
|
|
|
{},
|
|
|
|
{}
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"Allow": "GET, POST, HEAD",
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Expires": "Wed, 21 Oct 2015 07:28:00 GMT",
|
|
|
|
"Foo": "Bar"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Expires": "Wed, 21 Oct 2015 07:28:00 GMT",
|
|
|
|
"Foo": "Bar"
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
{
|
|
|
|
"Allow": "GET, POST, HEAD",
|
|
|
|
"Content-Location": "/test"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Content-Location": "/test"
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
for header, expected in tests:
|
|
|
|
assert helpers.remove_entity_headers(header) == expected
|