pytest_httpserver 1.1.0__tar.gz → 1.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/CHANGES.rst +14 -0
  2. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/PKG-INFO +3 -2
  3. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/README.md +1 -1
  4. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/conf.py +1 -1
  5. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/howto.rst +11 -0
  6. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pyproject.toml +5 -7
  7. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/httpserver.py +16 -0
  8. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/pytest_plugin.py +3 -3
  9. pytest_httpserver-1.1.1/tests/examples/test_howto_custom_request_matcher.py +37 -0
  10. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_blocking_httpserver.py +2 -2
  11. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_log_leak.py +1 -1
  12. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_log_querying.py +1 -1
  13. pytest_httpserver-1.1.1/tests/test_matcher.py +11 -0
  14. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_mixed.py +1 -1
  15. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_port_changing.py +1 -1
  16. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_release.py +11 -4
  17. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_ssl.py +11 -4
  18. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_threaded.py +1 -9
  19. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/CONTRIBUTION.md +0 -0
  20. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/LICENSE +0 -0
  21. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/Makefile +0 -0
  22. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/_static/.placeholder +0 -0
  23. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/api.rst +0 -0
  24. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/background.rst +0 -0
  25. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/changes.rst +0 -0
  26. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/fixtures.rst +0 -0
  27. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/guide.rst +0 -0
  28. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/index.rst +0 -0
  29. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/patch.py +0 -0
  30. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/tutorial.rst +0 -0
  31. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/doc/upgrade.rst +0 -0
  32. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/example.py +0 -0
  33. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/example_pytest.py +0 -0
  34. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/__init__.py +7 -7
  35. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/blocking_httpserver.py +0 -0
  36. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/hooks.py +0 -0
  37. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/pytest_httpserver/py.typed +0 -0
  38. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/Makefile +0 -0
  39. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/README +0 -0
  40. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/rootCA.cnf +0 -0
  41. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/rootCA.crt +0 -0
  42. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/rootCA.key +0 -0
  43. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/rootCA.srl +0 -0
  44. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/server.cnf +0 -0
  45. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/server.crt +0 -0
  46. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/server.csr +0 -0
  47. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/server.key +0 -0
  48. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/assets/v3.ext +0 -0
  49. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/conftest.py +0 -0
  50. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_example_blocking_httpserver.py +0 -0
  51. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_example_query_params1.py +0 -0
  52. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_example_query_params2.py +0 -0
  53. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_authorization_headers.py +0 -0
  54. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_case_insensitive_matcher.py +0 -0
  55. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_check.py +0 -0
  56. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_check_handler_errors.py +0 -0
  57. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_custom_handler.py +0 -0
  58. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_custom_hooks.py +0 -0
  59. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_header_value_matcher.py +0 -0
  60. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_hooks.py +0 -0
  61. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_json_matcher.py +0 -0
  62. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_log_querying.py +0 -0
  63. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_query_params_dict.py +0 -0
  64. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_query_params_never_do_this.py +0 -0
  65. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_query_params_proper_use.py +0 -0
  66. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_regexp.py +0 -0
  67. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_timeout_requests.py +0 -0
  68. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_url_matcher.py +0 -0
  69. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/examples/test_howto_wait_success.py +0 -0
  70. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_handler_errors.py +0 -0
  71. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_headers.py +0 -0
  72. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_hooks.py +0 -0
  73. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_ip_protocols.py +0 -0
  74. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_json_matcher.py +0 -0
  75. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_oneshot.py +0 -0
  76. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_ordered.py +0 -0
  77. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_parse_qs.py +0 -0
  78. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_permanent.py +0 -0
  79. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_querymatcher.py +0 -0
  80. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_querystring.py +0 -0
  81. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_urimatch.py +0 -0
  82. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_wait.py +0 -0
  83. {pytest_httpserver-1.1.0 → pytest_httpserver-1.1.1}/tests/test_with_statement.py +0 -0
@@ -2,6 +2,20 @@
2
2
  Release Notes
3
3
  =============
4
4
 
5
+ .. _Release Notes_1.1.1:
6
+
7
+ 1.1.1
8
+ =====
9
+
10
+ .. _Release Notes_1.1.1_New Features:
11
+
12
+ New Features
13
+ ------------
14
+
15
+ - Add a new ``expect`` method to the ``HTTPServer`` object which allows
16
+ developers to provide their own request matcher object.
17
+
18
+
5
19
  .. _Release Notes_1.1.0:
6
20
 
7
21
  1.1.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest_httpserver
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: pytest-httpserver is a httpserver for pytest
5
5
  Home-page: https://github.com/csernazs/pytest-httpserver
6
6
  License: MIT
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.9
18
18
  Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
21
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
23
  Requires-Dist: Werkzeug (>=2.0.0)
23
24
  Project-URL: Bug Tracker, https://github.com/csernazs/pytest-httpserver/issues
@@ -25,7 +26,7 @@ Project-URL: Documentation, https://pytest-httpserver.readthedocs.io/en/latest/
25
26
  Project-URL: Repository, https://github.com/csernazs/pytest-httpserver
26
27
  Description-Content-Type: text/markdown
27
28
 
28
- [![Build Status](https://github.com/csernazs/pytest-httpserver/workflows/build/badge.svg?branch=master)](https://github.com/csernazs/pytest-httpserver/actions?query=workflow%3Abuild+branch%3Amaster)
29
+ [![Build Status](https://github.com/csernazs/pytest-httpserver/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/csernazs/pytest-httpserver/actions?query=workflow%3Abuild+branch%3Amaster)
29
30
  [![Documentation Status](https://readthedocs.org/projects/pytest-httpserver/badge/?version=latest)](https://pytest-httpserver.readthedocs.io/en/latest/?badge=latest)
30
31
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
31
32
  [![codecov](https://codecov.io/gh/csernazs/pytest-httpserver/branch/master/graph/badge.svg?token=MX2JXbHqRH)](https://codecov.io/gh/csernazs/pytest-httpserver)
@@ -1,4 +1,4 @@
1
- [![Build Status](https://github.com/csernazs/pytest-httpserver/workflows/build/badge.svg?branch=master)](https://github.com/csernazs/pytest-httpserver/actions?query=workflow%3Abuild+branch%3Amaster)
1
+ [![Build Status](https://github.com/csernazs/pytest-httpserver/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/csernazs/pytest-httpserver/actions?query=workflow%3Abuild+branch%3Amaster)
2
2
  [![Documentation Status](https://readthedocs.org/projects/pytest-httpserver/badge/?version=latest)](https://pytest-httpserver.readthedocs.io/en/latest/?badge=latest)
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
4
  [![codecov](https://codecov.io/gh/csernazs/pytest-httpserver/branch/master/graph/badge.svg?token=MX2JXbHqRH)](https://codecov.io/gh/csernazs/pytest-httpserver)
@@ -68,7 +68,7 @@ author = "Zsolt Cserna"
68
68
  # built documents.
69
69
  #
70
70
  # The short X.Y version.
71
- version = "1.1.0"
71
+ version = "1.1.1"
72
72
  # The full version, including alpha/beta/rc tags.
73
73
  release = version
74
74
 
@@ -238,6 +238,17 @@ these.
238
238
  the server.
239
239
 
240
240
 
241
+ Using custom request matcher
242
+ ----------------------------
243
+ In the case when you want to extend or modify the request matcher in
244
+ *pytest-httpserrver*, then you can use your own request matcher.
245
+
246
+ Example:
247
+
248
+ .. literalinclude :: ../tests/examples/test_howto_custom_request_matcher.py
249
+ :language: python
250
+
251
+
241
252
  Customizing host and port
242
253
  -------------------------
243
254
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pytest_httpserver"
3
- version = "1.1.0"
3
+ version = "1.1.1"
4
4
  description = "pytest-httpserver is a httpserver for pytest"
5
5
  authors = ["Zsolt Cserna <cserna.zsolt@gmail.com>"]
6
6
  license = "MIT"
@@ -41,14 +41,13 @@ optional = true
41
41
  pre-commit = ">=2.20,<4.0"
42
42
  requests = "*"
43
43
  Sphinx = ">=5.1.1,<8.0.0"
44
- sphinx-rtd-theme = ">=1,<3"
44
+ sphinx-rtd-theme = ">=1,<4"
45
45
  reno = "*"
46
46
  types-requests = "*"
47
47
  pytest = ">=7.1.3,<9.0.0"
48
48
  pytest-cov = ">=3,<6"
49
49
  coverage = ">=6.4.4,<8.0.0"
50
- types-toml = "*"
51
- toml = "^0.10.2"
50
+ tomli = { version = "*", markers = "python_version < '3.11'"}
52
51
  black = "*"
53
52
  ruff = "*"
54
53
  mypy = "*"
@@ -59,7 +58,7 @@ optional = true
59
58
 
60
59
  [tool.poetry.group.doc.dependencies]
61
60
  Sphinx = ">=5.1.1,<8.0.0"
62
- sphinx-rtd-theme = ">=1,<3"
61
+ sphinx-rtd-theme = ">=1,<4"
63
62
 
64
63
 
65
64
  [tool.poetry.group.test]
@@ -72,8 +71,7 @@ coverage = "*"
72
71
  requests = "*"
73
72
  types-requests = "*"
74
73
  pre-commit = "*"
75
- types-toml = "*"
76
- toml = "*"
74
+ tomli = { version = "*", markers = "python_version < '3.11'"}
77
75
  mypy = "*"
78
76
 
79
77
  [build-system]
@@ -972,6 +972,22 @@ class HTTPServer(HTTPServerBase): # pylint: disable=too-many-instance-attribute
972
972
  self.oneshot_handlers = RequestHandlerList()
973
973
  self.handlers = RequestHandlerList()
974
974
 
975
+ def expect(self, matcher: RequestMatcher, handler_type: HandlerType = HandlerType.PERMANENT) -> RequestHandler:
976
+ """
977
+ Create and register a request handler.
978
+
979
+ :param matcher: :py:class:`RequestMatcher` used to match requests.
980
+ :param handler_type: type of handler
981
+ """
982
+ request_handler = RequestHandler(matcher)
983
+ if handler_type == HandlerType.PERMANENT:
984
+ self.handlers.append(request_handler)
985
+ elif handler_type == HandlerType.ONESHOT:
986
+ self.oneshot_handlers.append(request_handler)
987
+ elif handler_type == HandlerType.ORDERED:
988
+ self.ordered_handlers.append(request_handler)
989
+ return request_handler
990
+
975
991
  def expect_request(
976
992
  self,
977
993
  uri: str | URIPattern | Pattern[str],
@@ -61,7 +61,7 @@ def pytest_sessionfinish(session, exitstatus): # noqa: ARG001
61
61
  Plugin.SERVER.stop()
62
62
 
63
63
 
64
- @pytest.fixture()
64
+ @pytest.fixture
65
65
  def httpserver(make_httpserver):
66
66
  server = make_httpserver
67
67
  server.clear()
@@ -78,7 +78,7 @@ def make_httpserver_ipv4(httpserver_ssl_context):
78
78
  server.stop()
79
79
 
80
80
 
81
- @pytest.fixture()
81
+ @pytest.fixture
82
82
  def httpserver_ipv4(make_httpserver_ipv4):
83
83
  server = make_httpserver_ipv4
84
84
  server.clear()
@@ -95,7 +95,7 @@ def make_httpserver_ipv6(httpserver_ssl_context):
95
95
  server.stop()
96
96
 
97
97
 
98
- @pytest.fixture()
98
+ @pytest.fixture
99
99
  def httpserver_ipv6(make_httpserver_ipv6):
100
100
  server = make_httpserver_ipv6
101
101
  server.clear()
@@ -0,0 +1,37 @@
1
+ import requests
2
+ from werkzeug import Request
3
+
4
+ from pytest_httpserver import HTTPServer
5
+ from pytest_httpserver import RequestMatcher
6
+
7
+
8
+ class MyMatcher(RequestMatcher):
9
+ def match(self, request: Request) -> bool:
10
+ match = super().match(request)
11
+ if not match: # existing parameters didn't match -> return with False
12
+ return match
13
+
14
+ # match the json's "value" key: if it is an integer and it is an even
15
+ # number, it returns True
16
+ json = request.json
17
+ if isinstance(json, dict) and isinstance(json.get("value"), int):
18
+ return json["value"] % 2 == 0
19
+
20
+ return False
21
+
22
+
23
+ def test_custom_request_matcher(httpserver: HTTPServer):
24
+ httpserver.expect(MyMatcher("/foo")).respond_with_data("OK")
25
+
26
+ # with even number it matches the request
27
+ resp = requests.post(httpserver.url_for("/foo"), json={"value": 42})
28
+ resp.raise_for_status()
29
+ assert resp.text == "OK"
30
+
31
+ resp = requests.post(httpserver.url_for("/foo"), json={"value": 198})
32
+ resp.raise_for_status()
33
+ assert resp.text == "OK"
34
+
35
+ # with an odd number, it does not match the request
36
+ resp = requests.post(httpserver.url_for("/foo"), json={"value": 43})
37
+ assert resp.status_code == 500
@@ -40,7 +40,7 @@ def then_the_response_is_got_from(server_connection, response):
40
40
  assert server_connection.get(timeout=9).json() == response
41
41
 
42
42
 
43
- @pytest.fixture()
43
+ @pytest.fixture
44
44
  def httpserver():
45
45
  server = BlockingHTTPServer(timeout=1)
46
46
  server.start()
@@ -122,4 +122,4 @@ def test_raises_assertion_error_when_request_was_not_responded(httpserver: Block
122
122
 
123
123
 
124
124
  def test_repr(httpserver: BlockingHTTPServer):
125
- assert repr(httpserver) == f"<BlockingHTTPServer host=localhost port={httpserver.port}>"
125
+ assert repr(httpserver) == f"<BlockingHTTPServer host={httpserver.host} port={httpserver.port}>"
@@ -13,7 +13,7 @@ class Client:
13
13
  requests.get(self.url)
14
14
 
15
15
 
16
- @pytest.fixture()
16
+ @pytest.fixture
17
17
  def my_fixture():
18
18
  client = Client()
19
19
  yield client
@@ -47,7 +47,7 @@ def test_verify_assert_msg(httpserver: HTTPServer):
47
47
  "Path: /foo",
48
48
  "Method: GET",
49
49
  "Body: b''",
50
- f"Headers: Host: localhost:{httpserver.port}",
50
+ f"Headers: Host: {httpserver.host}:{httpserver.port}",
51
51
  "User-Agent: requests",
52
52
  "Accept-Encoding: gzip, deflate",
53
53
  "Accept: */*",
@@ -0,0 +1,11 @@
1
+ import requests
2
+
3
+ from pytest_httpserver import HTTPServer
4
+
5
+
6
+ def test_expect_method(httpserver: HTTPServer):
7
+ expected_response = "OK"
8
+ matcher = httpserver.create_matcher(uri="/test", method="POST")
9
+ httpserver.expect(matcher).respond_with_data(expected_response)
10
+ resp = requests.post(httpserver.url_for("/test"), json={"list": [1, 2, 3, 4]})
11
+ assert resp.text == expected_response
@@ -85,4 +85,4 @@ def test_all_ordered_missing(httpserver: HTTPServer):
85
85
 
86
86
 
87
87
  def test_repr(httpserver: HTTPServer):
88
- assert repr(httpserver) == f"<HTTPServer host=localhost port={httpserver.port}>"
88
+ assert repr(httpserver) == f"<HTTPServer host={httpserver.host} port={httpserver.port}>"
@@ -9,7 +9,7 @@ PORT_KEY = "PYTEST_HTTPSERVER_PORT"
9
9
  HOST_KEY = "PYTEST_HTTPSERVER_HOST"
10
10
 
11
11
 
12
- @pytest.fixture()
12
+ @pytest.fixture
13
13
  def tmpenv():
14
14
  old_vars = {}
15
15
  for key in (HOST_KEY, PORT_KEY):
@@ -11,7 +11,13 @@ from pathlib import Path
11
11
  from typing import Iterable
12
12
 
13
13
  import pytest
14
- import toml
14
+
15
+ try:
16
+ import tomllib
17
+ except ImportError:
18
+ # Unfortunately mypy cannot handle this try/expect pattern, and "type: ignore"
19
+ # is the simplest work-around. See: https://github.com/python/mypy/issues/1153
20
+ import tomli as tomllib # type: ignore
15
21
 
16
22
  # TODO: skip if poetry is not available or add mark to test it explicitly
17
23
 
@@ -20,7 +26,7 @@ pytestmark = pytest.mark.release
20
26
 
21
27
  NAME = "pytest-httpserver"
22
28
  NAME_UNDERSCORE = NAME.replace("-", "_")
23
- PY_MAX_VERSION = (3, 12)
29
+ PY_MAX_VERSION = (3, 13)
24
30
 
25
31
 
26
32
  @pytest.fixture(scope="session")
@@ -31,8 +37,8 @@ def pyproject_path() -> Path:
31
37
  @pytest.fixture(scope="session")
32
38
  def pyproject(pyproject_path: Path):
33
39
  assert pyproject_path.is_file()
34
- with pyproject_path.open() as infile:
35
- pyproject = toml.load(infile)
40
+ with pyproject_path.open("rb") as infile:
41
+ pyproject = tomllib.load(infile)
36
42
  return pyproject
37
43
 
38
44
 
@@ -228,6 +234,7 @@ def test_sdist_contents(build: Build, version: str):
228
234
  "test_urimatch.py",
229
235
  "test_wait.py",
230
236
  "test_with_statement.py",
237
+ "test_matcher.py",
231
238
  },
232
239
  }
233
240
 
@@ -5,6 +5,8 @@ from os.path import join as pjoin
5
5
  import pytest
6
6
  import requests
7
7
 
8
+ from pytest_httpserver import HTTPServer
9
+
8
10
  pytestmark = pytest.mark.ssl
9
11
 
10
12
  test_dir = os.path.dirname(os.path.realpath(__file__))
@@ -24,18 +26,23 @@ def httpserver_ssl_context():
24
26
  return ssl.SSLContext(protocol)
25
27
 
26
28
 
27
- def test_ssl(httpserver):
29
+ def test_ssl(httpserver: HTTPServer):
28
30
  server_crt = pjoin(assets_dir, "server.crt")
29
31
  server_key = pjoin(assets_dir, "server.key")
30
32
  root_ca = pjoin(assets_dir, "rootCA.crt")
31
- context = httpserver.ssl_context
32
33
 
33
34
  assert (
34
- context is not None
35
+ httpserver.ssl_context is not None
35
36
  ), "SSLContext not set. The session was probably started with a test that did not define an SSLContext."
36
37
 
37
38
  httpserver.ssl_context.load_cert_chain(server_crt, server_key)
38
39
  httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"})
39
40
 
40
41
  assert httpserver.is_running()
41
- assert requests.get(httpserver.url_for("/foobar"), verify=root_ca).json() == {"foo": "bar"}
42
+
43
+ assert httpserver.url_for("/").startswith("https://")
44
+
45
+ # ensure we are using "localhost" and not "127.0.0.1" to pass cert verification
46
+ url = f"https://localhost:{httpserver.port}/foobar"
47
+
48
+ assert requests.get(url, verify=root_ca).json() == {"foo": "bar"}
@@ -10,7 +10,7 @@ from werkzeug import Response
10
10
  from pytest_httpserver import HTTPServer
11
11
 
12
12
 
13
- @pytest.fixture()
13
+ @pytest.fixture
14
14
  def threaded() -> Iterable[HTTPServer]:
15
15
  server = HTTPServer(threaded=True)
16
16
  server.start()
@@ -33,8 +33,6 @@ def test_threaded(threaded: HTTPServer):
33
33
 
34
34
  threaded.expect_request("/foo").respond_with_handler(handler)
35
35
 
36
- t_start = time.perf_counter()
37
-
38
36
  number_of_connections = 5
39
37
  conns = [http.client.HTTPConnection(threaded.host, threaded.port) for _ in range(number_of_connections)]
40
38
 
@@ -51,10 +49,4 @@ def test_threaded(threaded: HTTPServer):
51
49
  for conn in conns:
52
50
  conn.close()
53
51
 
54
- t_elapsed = time.perf_counter() - t_start
55
-
56
52
  assert len(thread_ids) == len(set(thread_ids)), "thread ids returned should be unique"
57
-
58
- assert (
59
- t_elapsed < number_of_connections * sleep_time * 0.9
60
- ), "elapsed time should be less than processing sequential requests"
@@ -4,19 +4,19 @@ This is package provides the main API for the pytest_httpserver package.
4
4
  """
5
5
 
6
6
  __all__ = [
7
+ "METHOD_ALL",
8
+ "URI_DEFAULT",
9
+ "BlockingHTTPServer",
10
+ "BlockingRequestHandler",
11
+ "Error",
7
12
  "HTTPServer",
8
13
  "HTTPServerError",
9
- "Error",
10
- "NoHandlerError",
11
- "WaitingSettings",
12
14
  "HeaderValueMatcher",
15
+ "NoHandlerError",
13
16
  "RequestHandler",
14
17
  "RequestMatcher",
15
18
  "URIPattern",
16
- "URI_DEFAULT",
17
- "METHOD_ALL",
18
- "BlockingHTTPServer",
19
- "BlockingRequestHandler",
19
+ "WaitingSettings",
20
20
  ]
21
21
 
22
22
  from .blocking_httpserver import BlockingHTTPServer