Skip to content

Commit f893f9e

Browse files
committed
Test the get_content_length function
This in turn ensures that the whitespace (leading or trailing) is stripped and the correct length is returned.
1 parent d3e0e01 commit f893f9e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/sansio/test_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from werkzeug.sansio.utils import get_content_length
56
from werkzeug.sansio.utils import get_host
67

78

@@ -30,3 +31,23 @@ def test_get_host(
3031
expected: str,
3132
) -> None:
3233
assert get_host(scheme, host_header, server) == expected
34+
35+
36+
@pytest.mark.parametrize(
37+
("http_content_length", "http_transfer_encoding", "expected"),
38+
[
39+
("2", None, 2),
40+
(" 2", None, 2),
41+
("2 ", None, 2),
42+
(None, None, None),
43+
(None, "chunked", None),
44+
("a", None, 0),
45+
("-2", None, 0),
46+
],
47+
)
48+
def test_get_content_length(
49+
http_content_length: str | None,
50+
http_transfer_encoding: str | None,
51+
expected: int | None,
52+
) -> None:
53+
assert get_content_length(http_content_length, http_transfer_encoding) == expected

0 commit comments

Comments
 (0)