aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest-localserver/py3/tests/test_http.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-02-02 10:11:17 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-02-02 10:21:23 +0300
commit637f8bbf610e99859dfbdbde49d99e9c60a7acf7 (patch)
tree3e685433e89f53a34ca2a4635c29865598d12b4f /contrib/python/pytest-localserver/py3/tests/test_http.py
parentbbd3eacdd0520f608b6290efdd0050d7e55ad40d (diff)
downloadydb-637f8bbf610e99859dfbdbde49d99e9c60a7acf7.tar.gz
Intermediate changes
commit_hash:20c3eb2f2d78b5f654ec928c071692413a1bd96d
Diffstat (limited to 'contrib/python/pytest-localserver/py3/tests/test_http.py')
-rw-r--r--contrib/python/pytest-localserver/py3/tests/test_http.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/contrib/python/pytest-localserver/py3/tests/test_http.py b/contrib/python/pytest-localserver/py3/tests/test_http.py
index 64859ffd25..904e6aea5e 100644
--- a/contrib/python/pytest-localserver/py3/tests/test_http.py
+++ b/contrib/python/pytest-localserver/py3/tests/test_http.py
@@ -5,6 +5,7 @@ import textwrap
import pytest
import requests
+from werkzeug.exceptions import ClientDisconnected
from pytest_localserver import http
from pytest_localserver import plugin
@@ -90,6 +91,29 @@ def test_HEAD_request(httpserver):
# assert resp.status_code == 200
+def test_POST_request_no_store_data(httpserver):
+ headers = {"Content-type": "text/plain"}
+ httpserver.serve_content("TEST!", store_request_data=False)
+ requests.post(httpserver.url, data=b"testdata", headers=headers)
+
+ request = httpserver.requests[-1]
+ request.input_stream.close()
+
+ with pytest.raises(ClientDisconnected):
+ request.data
+
+
+def test_POST_request_store_data(httpserver):
+ headers = {"Content-type": "text/plain"}
+ httpserver.serve_content("TEST!", store_request_data=True)
+ requests.post(httpserver.url, data=b"testdata", headers=headers)
+
+ request = httpserver.requests[-1]
+ request.input_stream.close()
+
+ assert httpserver.requests[-1].data == b"testdata"
+
+
@pytest.mark.parametrize("chunked_flag", [http.Chunked.YES, http.Chunked.AUTO, http.Chunked.NO])
def test_chunked_attribute_without_header(httpserver, chunked_flag):
"""
@@ -224,7 +248,7 @@ def _compare_chunks(expected, actual):
__tracebackhide__ = True
if expected != actual:
message = [_format_chunk(expected) + " != " + _format_chunk(actual)]
- if type(expected) == type(actual):
+ if type(expected) is type(actual):
for i, (e, a) in enumerate(itertools.zip_longest(expected, actual, fillvalue="<end>")):
if e != a:
message += [
@@ -274,19 +298,23 @@ def test_GET_request_chunked_no_content_length(httpserver, chunked_flag):
def test_httpserver_init_failure_no_stderr_during_cleanup(tmp_path):
"""
Test that, when the server encounters an error during __init__, its cleanup
- does not raise an AttributeError in its __del__ method, which would emit a
+ does not raise an AttributeError in its __del__ method, which would emit a
warning onto stderr.
"""
script_path = tmp_path.joinpath("script.py")
- script_path.write_text(textwrap.dedent("""
+ script_path.write_text(
+ textwrap.dedent(
+ """
from pytest_localserver import http
from unittest.mock import patch
with patch("pytest_localserver.http.make_server", side_effect=RuntimeError("init failure")):
server = http.ContentServer()
- """))
+ """
+ )
+ )
result = subprocess.run([sys.executable, str(script_path)], stderr=subprocess.PIPE)