From 40278eaf0669e4a3344b24e3bf545feab8b14bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 2 Dec 2024 08:09:17 +0800 Subject: [PATCH] Fix test cases for compatibility with httpx 0.28.0. --- pyproject.toml | 2 +- tests/test_utils.py | 20 ++++++++++++-------- tests/testlib.py | 4 +++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0c8ad84..3938876 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ dependencies = [ [project.optional-dependencies] devel = [ - "httpx", + "httpx >= 0.20.0", "OpenCC", ] diff --git a/tests/test_utils.py b/tests/test_utils.py index 27a2dee..4027e59 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -67,8 +67,9 @@ class NextUriTestCase(unittest.TestCase): self.__app.add_url_rule("/test-next", view_func=test_next_uri_view, methods=["GET", "POST"]) - client: httpx.Client = httpx.Client(app=self.__app, - base_url=TEST_SERVER) + client: httpx.Client = httpx.Client( + transport=httpx.WSGITransport(app=self.__app), + base_url=TEST_SERVER) client.headers["Referer"] = TEST_SERVER csrf_token: str = get_csrf_token(client) response: httpx.Response @@ -96,8 +97,9 @@ class NextUriTestCase(unittest.TestCase): self.__app.add_url_rule("/test-no-next", view_func=test_no_next_uri_view, methods=["GET", "POST"]) - client: httpx.Client = httpx.Client(app=self.__app, - base_url=TEST_SERVER) + client: httpx.Client = httpx.Client( + transport=httpx.WSGITransport(app=self.__app), + base_url=TEST_SERVER) client.headers["Referer"] = TEST_SERVER csrf_token: str = get_csrf_token(client) response: httpx.Response @@ -122,8 +124,9 @@ class NextUriTestCase(unittest.TestCase): self.__app.add_url_rule("/test-invalid-next", view_func=test_invalid_next_uri_view, methods=["GET", "POST"]) - client: httpx.Client = httpx.Client(app=self.__app, - base_url=TEST_SERVER) + client: httpx.Client = httpx.Client( + transport=httpx.WSGITransport(app=self.__app), + base_url=TEST_SERVER) client.headers["Referer"] = TEST_SERVER csrf_token: str = get_csrf_token(client) next_uri: str @@ -227,8 +230,9 @@ class PaginationTestCase(unittest.TestCase): self.assertEqual(pagination.list, self.__params.result) return "" - self.__client: httpx.Client = httpx.Client(app=self.__app, - base_url=TEST_SERVER) + self.__client: httpx.Client = httpx.Client( + transport=httpx.WSGITransport(app=self.__app), + base_url=TEST_SERVER) """The user client.""" self.__client.headers["Referer"] = TEST_SERVER diff --git a/tests/testlib.py b/tests/testlib.py index ff1d5b0..636aece 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -96,7 +96,9 @@ def get_client(app: Flask, username: str) -> httpx.Client: :param username: The username. :return: The user client. """ - client: httpx.Client = httpx.Client(app=app, base_url=TEST_SERVER) + client: httpx.Client = httpx.Client( + transport=httpx.WSGITransport(app=app), + base_url=TEST_SERVER) client.headers["Referer"] = TEST_SERVER csrf_token: str = get_csrf_token(client) with app.app_context():