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

Use literals in place of HTTPStatus constants in tests #13479

Merged
merged 5 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13479.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use literals in place of `HTTPStatus` constants in tests.
7 changes: 3 additions & 4 deletions tests/rest/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import urllib.parse
from http import HTTPStatus

from parameterized import parameterized

Expand Down Expand Up @@ -79,10 +78,10 @@ def _ensure_quarantined(

# Should be quarantined
self.assertEqual(
HTTPStatus.NOT_FOUND,
404,
channel.code,
msg=(
"Expected to receive a HTTPStatus.NOT_FOUND on accessing quarantined media: %s"
"Expected to receive a 404 on accessing quarantined media: %s"
% server_and_media_id
),
)
Expand All @@ -107,7 +106,7 @@ def test_quarantine_media_requires_admin(self, url: str) -> None:

# Expect a forbidden error
self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg="Expected forbidden on quarantining media as a non-admin",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/admin/test_background_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
)
def test_requester_is_no_admin(self, method: str, url: str) -> None:
"""
If the user is not a server admin, an error HTTPStatus.FORBIDDEN is returned.
If the user is not a server admin, an error 403 is returned.
"""

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

self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
self.assertEqual(403, channel.code, msg=channel.json_body)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

def test_invalid_parameter(self) -> None:
Expand Down
28 changes: 14 additions & 14 deletions tests/rest/admin/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_no_auth(self, method: str) -> None:
channel = self.make_request(method, self.url, b"{}")

self.assertEqual(
HTTPStatus.UNAUTHORIZED,
401,
channel.code,
msg=channel.json_body,
)
Expand All @@ -76,7 +76,7 @@ def test_requester_is_no_admin(self, method: str) -> None:
)

self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg=channel.json_body,
)
Expand All @@ -85,7 +85,7 @@ def test_requester_is_no_admin(self, method: str) -> None:
@parameterized.expand(["GET", "PUT", "DELETE"])
def test_user_does_not_exist(self, method: str) -> None:
"""
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
Tests that a lookup for a user that does not exist returns a 404
"""
url = (
"/_synapse/admin/v2/users/@unknown_person:test/devices/%s"
Expand All @@ -98,7 +98,7 @@ def test_user_does_not_exist(self, method: str) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

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

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

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

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

self.assertEqual(
HTTPStatus.UNAUTHORIZED,
401,
channel.code,
msg=channel.json_body,
)
Expand All @@ -331,15 +331,15 @@ def test_requester_is_no_admin(self) -> None:
)

self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

def test_user_does_not_exist(self) -> None:
"""
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
Tests that a lookup for a user that does not exist returns a 404
"""
url = "/_synapse/admin/v2/users/@unknown_person:test/devices"
channel = self.make_request(
Expand All @@ -348,7 +348,7 @@ def test_user_does_not_exist(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

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

self.assertEqual(
HTTPStatus.UNAUTHORIZED,
401,
channel.code,
msg=channel.json_body,
)
Expand All @@ -457,15 +457,15 @@ def test_requester_is_no_admin(self) -> None:
)

self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

def test_user_does_not_exist(self) -> None:
"""
Tests that a lookup for a user that does not exist returns a HTTPStatus.NOT_FOUND
Tests that a lookup for a user that does not exist returns a 404
"""
url = "/_synapse/admin/v2/users/@unknown_person:test/delete_devices"
channel = self.make_request(
Expand All @@ -474,7 +474,7 @@ def test_user_does_not_exist(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

def test_user_is_not_local(self) -> None:
Expand Down
16 changes: 8 additions & 8 deletions tests/rest/admin/test_event_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ def test_no_auth(self) -> None:
channel = self.make_request("GET", self.url, b"{}")

self.assertEqual(
HTTPStatus.UNAUTHORIZED,
401,
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])

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

channel = self.make_request(
Expand All @@ -100,7 +100,7 @@ def test_requester_is_no_admin(self) -> None:
)

self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg=channel.json_body,
)
Expand Down Expand Up @@ -467,15 +467,15 @@ def test_no_auth(self) -> None:
channel = self.make_request("GET", self.url, b"{}")

self.assertEqual(
HTTPStatus.UNAUTHORIZED,
401,
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])

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

channel = self.make_request(
Expand All @@ -485,7 +485,7 @@ def test_requester_is_no_admin(self) -> None:
)

self.assertEqual(
HTTPStatus.FORBIDDEN,
403,
channel.code,
msg=channel.json_body,
)
Expand Down Expand Up @@ -566,7 +566,7 @@ def test_invalid_report_id(self) -> None:

def test_report_id_not_found(self) -> None:
"""
Testing that a not existing `report_id` returns a HTTPStatus.NOT_FOUND.
Testing that a not existing `report_id` returns a 404.
"""

channel = self.make_request(
Expand All @@ -576,7 +576,7 @@ def test_report_id_not_found(self) -> None:
)

self.assertEqual(
HTTPStatus.NOT_FOUND,
404,
channel.code,
msg=channel.json_body,
)
Expand Down
10 changes: 5 additions & 5 deletions tests/rest/admin/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_requester_is_no_admin(self, method: str, url: str) -> None:
access_token=other_user_tok,
)

self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
self.assertEqual(403, channel.code, msg=channel.json_body)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

def test_invalid_parameter(self) -> None:
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

# invalid destination
Expand All @@ -127,7 +127,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

def test_limit(self) -> None:
Expand Down Expand Up @@ -561,7 +561,7 @@ def test_requester_is_no_admin(self) -> None:
access_token=other_user_tok,
)

self.assertEqual(HTTPStatus.FORBIDDEN, channel.code, msg=channel.json_body)
self.assertEqual(403, channel.code, msg=channel.json_body)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])

def test_invalid_parameter(self) -> None:
Expand Down Expand Up @@ -604,7 +604,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.NOT_FOUND, channel.code, msg=channel.json_body)
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

def test_limit(self) -> None:
Expand Down
Loading