Skip to content
Myr

Unit test for string containing multi-byte UTF-8

Before adoption: this commit came in with the history the project adopted, so no landing records it.

There are two tests here. One demonstrating existing, correct behavior for `data=bytes`, and another, failing, test for the case where `data=string` and the string contains multi-byte UTF-8.

authored by Bruce Adams · committed by Bruce Adams · parent 0b4d494 · Browse files · 1 file+17 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−0 removed

  • tests:+17 added−0 removed

1 file+17 added−0 removed

modified:tests/test_requests.py+17 added
1806 unmodified lines
1807 p = req.prepare()18081809 assert p.headers["Content-Length"] == length18101811 def test_content_length_for_bytes_data(self, httpbin):1812 data = "This is a string containing multi-byte UTF-8 ☃️"1813 encoded_data = data.encode("utf-8")1814 length = str(len(encoded_data))1815 req = requests.Request("POST", httpbin("post"), data=encoded_data)1816 p = req.prepare()18171818 assert p.headers["Content-Length"] == length18191820 def test_content_length_for_string_data_counts_bytes(self, httpbin):1821 data = "This is a string containing multi-byte UTF-8 ☃️"1822 length = str(len(data.encode("utf-8")))1823 req = requests.Request("POST", httpbin("post"), data=data)1824 p = req.prepare()18251826 assert p.headers["Content-Length"] == length18271828 def test_nonhttp_schemes_dont_check_URLs(self):1829 test_urls = (1830 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",1831 "file:///etc/passwd",
983 unmodified lines