Skip to content

Commit 3065798

Browse files
committed
refactor(http): adopt native HTTPX2 client interface
Remove the obsolete Requests-shaped compatibility layers from both the outbound client and its HTTP test harness. Native HTTPX2 request and response semantics reduce duplicate adapters, improve typing, and preserve redirect streaming and SSRF address-pinning coverage.
1 parent 2e546dc commit 3065798

18 files changed

Lines changed: 2167 additions & 2083 deletions

File tree

weblate/accounts/tests/test_avatars.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from weblate.accounts.apps import check_avatars
1717
from weblate.auth.models import User
1818
from weblate.trans.tests.test_views import FixtureTestCase
19-
from weblate.utils.tests import http_mock as responses
19+
from weblate.utils.tests import http_mock
2020

2121
TEST_URL = (
2222
"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=identicon&s=32"
@@ -44,13 +44,13 @@ def test_fallback_avatar_uses_stable_url(self) -> None:
4444
"https://cdn.example.com/static/api-32.png",
4545
)
4646

47-
@responses.activate
47+
@http_mock.activate
4848
def test_avatar(self) -> None:
4949
image = Image.new("RGB", (32, 32))
5050
storage = BytesIO()
5151
image.save(storage, "PNG")
5252
imagedata = storage.getvalue()
53-
responses.add(responses.GET, TEST_URL, body=imagedata)
53+
http_mock.register("GET", TEST_URL, content=imagedata)
5454
# Real user
5555
response = self.client.get(
5656
reverse("user_avatar", kwargs={"user": self.user.username, "size": 32})
@@ -64,9 +64,9 @@ def test_avatar(self) -> None:
6464
self.assert_png(response)
6565
self.assertEqual(response.content, imagedata)
6666

67-
@responses.activate
67+
@http_mock.activate
6868
def test_avatar_error(self) -> None:
69-
responses.add(responses.GET, TEST_URL, status=503)
69+
http_mock.register("GET", TEST_URL, status_code=503)
7070
# Choose different username to avoid using cache
7171
self.user.username = "test2"
7272
self.user.save()
@@ -86,13 +86,13 @@ def test_avatar_check_handles_http_error(self) -> None:
8686
self.assertEqual(len(errors), 1)
8787
self.assertEqual(errors[0].id, "weblate.E018")
8888

89-
@responses.activate
89+
@http_mock.activate
9090
def test_avatar_rejects_unsupported_size_before_fetch(self) -> None:
9191
response = self.client.get(
9292
reverse("user_avatar", kwargs={"user": self.user.username, "size": 999})
9393
)
9494
self.assertEqual(response.status_code, 404)
95-
self.assertEqual(len(responses.calls), 0)
95+
self.assertEqual(len(http_mock.calls), 0)
9696

9797
def test_anonymous_avatar(self) -> None:
9898
anonymous = User.objects.get(username="anonymous")

0 commit comments

Comments
 (0)