From 79d8967d9d51352d13f1f50f89ee83049a6b0021 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Wed, 26 Nov 2025 15:03:58 +0000 Subject: [PATCH] (Make the tests use assertEquals to tell us what they're seeing) --- tests/media/test_media_storage.py | 24 ++++++++++++------------ tests/rest/client/test_media.py | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/media/test_media_storage.py b/tests/media/test_media_storage.py index 28c4ce676a..30ecd5b2cb 100644 --- a/tests/media/test_media_storage.py +++ b/tests/media/test_media_storage.py @@ -1076,7 +1076,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxyz", shorthand=False, ) - assert channel.code == 200 + self.assertEquals(channel.code, 200) # next 15 should go through for i in range(15): @@ -1085,7 +1085,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): f"/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxy{i}", shorthand=False, ) - assert channel2.code == 200 + self.assertEquals(channel2.code, 200) # 17th will hit ratelimit channel3 = self.make_request( @@ -1093,7 +1093,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxyx", shorthand=False, ) - assert channel3.code == 429 + self.assertEquals(channel3.code, 429) # however, a request from a different IP will go through channel4 = self.make_request( @@ -1102,7 +1102,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): shorthand=False, client_ip="187.233.230.159", ) - assert channel4.code == 200 + self.assertEquals(channel4.code, 200) # at 87Kib/s it should take about 2 minutes for enough to drain from bucket that another # 30MiB download is authorized - The last download was blocked at 503,316,480. @@ -1152,7 +1152,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxyz", shorthand=False, ) - assert channel.code == 200 + self.assertEquals(channel.code, 200) # immediate second request should fail channel = self.make_request( @@ -1160,7 +1160,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxy1", shorthand=False, ) - assert channel.code == 429 + self.assertEquals(channel.code, 429) # advance half a second self.reactor.pump([0.5]) @@ -1171,7 +1171,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxy2", shorthand=False, ) - assert channel.code == 429 + self.assertEquals(channel.code, 429) # advance another half second self.reactor.pump([0.5]) @@ -1182,7 +1182,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): "/_matrix/media/v3/download/remote.org/abcdefghijklmnopqrstuvwxy3", shorthand=False, ) - assert channel.code == 200 + self.assertEquals(channel.code, 200) @override_config( { @@ -1391,11 +1391,11 @@ class MediaRepoSizeModuleCallbackTestCase(unittest.HomeserverTestCase): def test_upload_allowed(self) -> None: self.helper.upload_media(SMALL_PNG, tok=self.tok, expect_code=200) - assert self.last_user_id == self.user - assert self.last_size == len(SMALL_PNG) + self.assertEquals(self.last_user_id, self.user) + self.assertEquals(self.last_size, len(SMALL_PNG)) def test_upload_not_allowed(self) -> None: self.mock_result = False self.helper.upload_media(SMALL_PNG, tok=self.tok, expect_code=413) - assert self.last_user_id == self.user - assert self.last_size == len(SMALL_PNG) + self.assertEquals(self.last_user_id, self.user) + self.assertEquals(self.last_size, len(SMALL_PNG)) diff --git a/tests/rest/client/test_media.py b/tests/rest/client/test_media.py index 91bf94b672..14c646855e 100644 --- a/tests/rest/client/test_media.py +++ b/tests/rest/client/test_media.py @@ -1753,7 +1753,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): shorthand=False, access_token=self.tok, ) - assert channel.code == 200 + self.assertEquals(channel.code, 200) # next 15 should go through for i in range(15): @@ -1763,7 +1763,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): shorthand=False, access_token=self.tok, ) - assert channel2.code == 200 + self.assertEquals(channel2.code, 200) # 17th will hit ratelimit channel3 = self.make_request( @@ -1772,7 +1772,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): shorthand=False, access_token=self.tok, ) - assert channel3.code == 429 + self.assertEquals(channel3.code, 429) # however, a request from a different IP will go through channel4 = self.make_request( @@ -1782,7 +1782,7 @@ class RemoteDownloadLimiterTestCase(unittest.HomeserverTestCase): client_ip="187.233.230.159", access_token=self.tok, ) - assert channel4.code == 200 + self.assertEquals(channel4.code, 200) # at 87Kib/s it should take about 2 minutes for enough to drain from bucket that another # 30MiB download is authorized - The last download was blocked at 503,316,480.