Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 1595052

Browse files
authored
Use literals in place of HTTPStatus constants in tests (#13479)
Replace - `HTTPStatus.NOT_FOUND` - `HTTPStatus.FORBIDDEN` - `HTTPStatus.UNAUTHORIZED` - `HTTPStatus.CONFLICT` - `HTTPStatus.CREATED` Signed-off-by: Dirk Klimpel <[email protected]>
1 parent 54fb517 commit 1595052

File tree

12 files changed

+141
-141
lines changed

12 files changed

+141
-141
lines changed

changelog.d/13479.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use literals in place of `HTTPStatus` constants in tests.

tests/rest/admin/test_admin.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import urllib.parse
16-
from http import HTTPStatus
1716

1817
from parameterized import parameterized
1918

@@ -79,10 +78,10 @@ def _ensure_quarantined(
7978

8079
# Should be quarantined
8180
self.assertEqual(
82-
HTTPStatus.NOT_FOUND,
81+
404,
8382
channel.code,
8483
msg=(
85-
"Expected to receive a HTTPStatus.NOT_FOUND on accessing quarantined media: %s"
84+
"Expected to receive a 404 on accessing quarantined media: %s"
8685
% server_and_media_id
8786
),
8887
)
@@ -107,7 +106,7 @@ def test_quarantine_media_requires_admin(self, url: str) -> None:
107106

108107
# Expect a forbidden error
109108
self.assertEqual(
110-
HTTPStatus.FORBIDDEN,
109+
403,
111110
channel.code,
112111
msg="Expected forbidden on quarantining media as a non-admin",
113112
)

tests/rest/admin/test_background_updates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
5151
)
5252
def test_requester_is_no_admin(self, method: str, url: str) -> None:
5353
"""
54-
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
54+
If the user is not a server admin, an error 403 is returned.
5555
"""
5656

5757
self.register_user("user", "pass", admin=False)
@@ -64,7 +64,7 @@ def test_requester_is_no_admin(self, method: str, url: str) -> None:
6464
access_token=other_user_tok,
6565
)
6666

67-
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
67+
self.assertEqual(403, channel.code, msg=channel.json_body)
6868
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
6969

7070
def test_invalid_parameter(self) -> None:

tests/rest/admin/test_device.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_no_auth(self, method: str) -> None:
5858
channel = self.make_request(method, self.url, b"{}")
5959

6060
self.assertEqual(
61-
HTTPStatus.UNAUTHORIZED,
61+
401,
6262
channel.code,
6363
msg=channel.json_body,
6464
)
@@ -76,7 +76,7 @@ def test_requester_is_no_admin(self, method: str) -> None:
7676
)
7777

7878
self.assertEqual(
79-
HTTPStatus.FORBIDDEN,
79+
403,
8080
channel.code,
8181
msg=channel.json_body,
8282
)
@@ -85,7 +85,7 @@ def test_requester_is_no_admin(self, method: str) -> None:
8585
@parameterized.expand(["GET", "PUT", "DELETE"])
8686
def test_user_does_not_exist(self, method: str) -> None:
8787
"""
88-
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
88+
Tests that a lookup for a user that does not exist returns a 404
8989
"""
9090
url = (
9191
"/_synapse/admin/v2/users/@unknown_person:test/devices/%s"
@@ -98,7 +98,7 @@ def test_user_does_not_exist(self, method: str) -> None:
9898
access_token=self.admin_user_tok,
9999
)
100100

101-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
101+
self.assertEqual(404, channel.code, msg=channel.json_body)
102102
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
103103

104104
@parameterized.expand(["GET", "PUT", "DELETE"])
@@ -122,7 +122,7 @@ def test_user_is_not_local(self, method: str) -> None:
122122

123123
def test_unknown_device(self) -> None:
124124
"""
125-
Tests that a lookup for a device that does not exist returns either HTTPStatus.NOT_FOUND or 200.
125+
Tests that a lookup for a device that does not exist returns either 404 or 200.
126126
"""
127127
url = "/_synapse/admin/v2/users/%s/devices/unknown_device" % urllib.parse.quote(
128128
self.other_user
@@ -134,7 +134,7 @@ def test_unknown_device(self) -> None:
134134
access_token=self.admin_user_tok,
135135
)
136136

137-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
137+
self.assertEqual(404, channel.code, msg=channel.json_body)
138138
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
139139

140140
channel = self.make_request(
@@ -312,7 +312,7 @@ def test_no_auth(self) -> None:
312312
channel = self.make_request("GET", self.url, b"{}")
313313

314314
self.assertEqual(
315-
HTTPStatus.UNAUTHORIZED,
315+
401,
316316
channel.code,
317317
msg=channel.json_body,
318318
)
@@ -331,15 +331,15 @@ def test_requester_is_no_admin(self) -> None:
331331
)
332332

333333
self.assertEqual(
334-
HTTPStatus.FORBIDDEN,
334+
403,
335335
channel.code,
336336
msg=channel.json_body,
337337
)
338338
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
339339

340340
def test_user_does_not_exist(self) -> None:
341341
"""
342-
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
342+
Tests that a lookup for a user that does not exist returns a 404
343343
"""
344344
url = "/_synapse/admin/v2/users/@unknown_person:test/devices"
345345
channel = self.make_request(
@@ -348,7 +348,7 @@ def test_user_does_not_exist(self) -> None:
348348
access_token=self.admin_user_tok,
349349
)
350350

351-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
351+
self.assertEqual(404, channel.code, msg=channel.json_body)
352352
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
353353

354354
def test_user_is_not_local(self) -> None:
@@ -438,7 +438,7 @@ def test_no_auth(self) -> None:
438438
channel = self.make_request("POST", self.url, b"{}")
439439

440440
self.assertEqual(
441-
HTTPStatus.UNAUTHORIZED,
441+
401,
442442
channel.code,
443443
msg=channel.json_body,
444444
)
@@ -457,15 +457,15 @@ def test_requester_is_no_admin(self) -> None:
457457
)
458458

459459
self.assertEqual(
460-
HTTPStatus.FORBIDDEN,
460+
403,
461461
channel.code,
462462
msg=channel.json_body,
463463
)
464464
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
465465

466466
def test_user_does_not_exist(self) -> None:
467467
"""
468-
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
468+
Tests that a lookup for a user that does not exist returns a 404
469469
"""
470470
url = "/_synapse/admin/v2/users/@unknown_person:test/delete_devices"
471471
channel = self.make_request(
@@ -474,7 +474,7 @@ def test_user_does_not_exist(self) -> None:
474474
access_token=self.admin_user_tok,
475475
)
476476

477-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
477+
self.assertEqual(404, channel.code, msg=channel.json_body)
478478
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
479479

480480
def test_user_is_not_local(self) -> None:

tests/rest/admin/test_event_reports.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ def test_no_auth(self) -> None:
8282
channel = self.make_request("GET", self.url, b"{}")
8383

8484
self.assertEqual(
85-
HTTPStatus.UNAUTHORIZED,
85+
401,
8686
channel.code,
8787
msg=channel.json_body,
8888
)
8989
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
9090

9191
def test_requester_is_no_admin(self) -> None:
9292
"""
93-
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
93+
If the user is not a server admin, an error 403 is returned.
9494
"""
9595

9696
channel = self.make_request(
@@ -100,7 +100,7 @@ def test_requester_is_no_admin(self) -> None:
100100
)
101101

102102
self.assertEqual(
103-
HTTPStatus.FORBIDDEN,
103+
403,
104104
channel.code,
105105
msg=channel.json_body,
106106
)
@@ -467,15 +467,15 @@ def test_no_auth(self) -> None:
467467
channel = self.make_request("GET", self.url, b"{}")
468468

469469
self.assertEqual(
470-
HTTPStatus.UNAUTHORIZED,
470+
401,
471471
channel.code,
472472
msg=channel.json_body,
473473
)
474474
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
475475

476476
def test_requester_is_no_admin(self) -> None:
477477
"""
478-
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
478+
If the user is not a server admin, an error 403 is returned.
479479
"""
480480

481481
channel = self.make_request(
@@ -485,7 +485,7 @@ def test_requester_is_no_admin(self) -> None:
485485
)
486486

487487
self.assertEqual(
488-
HTTPStatus.FORBIDDEN,
488+
403,
489489
channel.code,
490490
msg=channel.json_body,
491491
)
@@ -566,7 +566,7 @@ def test_invalid_report_id(self) -> None:
566566

567567
def test_report_id_not_found(self) -> None:
568568
"""
569-
Testing that a not existing `report_id` returns a HTTPStatus.NOT_FOUND.
569+
Testing that a not existing `report_id` returns a 404.
570570
"""
571571

572572
channel = self.make_request(
@@ -576,7 +576,7 @@ def test_report_id_not_found(self) -> None:
576576
)
577577

578578
self.assertEqual(
579-
HTTPStatus.NOT_FOUND,
579+
404,
580580
channel.code,
581581
msg=channel.json_body,
582582
)

tests/rest/admin/test_federation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_requester_is_no_admin(self, method: str, url: str) -> None:
6464
access_token=other_user_tok,
6565
)
6666

67-
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
67+
self.assertEqual(403, channel.code, msg=channel.json_body)
6868
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
6969

7070
def test_invalid_parameter(self) -> None:
@@ -117,7 +117,7 @@ def test_invalid_parameter(self) -> None:
117117
access_token=self.admin_user_tok,
118118
)
119119

120-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
120+
self.assertEqual(404, channel.code, msg=channel.json_body)
121121
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
122122

123123
# invalid destination
@@ -127,7 +127,7 @@ def test_invalid_parameter(self) -> None:
127127
access_token=self.admin_user_tok,
128128
)
129129

130-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
130+
self.assertEqual(404, channel.code, msg=channel.json_body)
131131
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
132132

133133
def test_limit(self) -> None:
@@ -561,7 +561,7 @@ def test_requester_is_no_admin(self) -> None:
561561
access_token=other_user_tok,
562562
)
563563

564-
self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
564+
self.assertEqual(403, channel.code, msg=channel.json_body)
565565
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
566566

567567
def test_invalid_parameter(self) -> None:
@@ -604,7 +604,7 @@ def test_invalid_parameter(self) -> None:
604604
access_token=self.admin_user_tok,
605605
)
606606

607-
self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
607+
self.assertEqual(404, channel.code, msg=channel.json_body)
608608
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
609609

610610
def test_limit(self) -> None:

0 commit comments

Comments
 (0)