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 #13488

Merged
merged 4 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use literals in place of HTTPStatus constants in tests
  • Loading branch information
dklimpel committed Aug 9, 2022
commit 32abb1ee885e8ad9cb6aeae87677d707ea2922cf
7 changes: 3 additions & 4 deletions tests/rest/admin/test_background_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from http import HTTPStatus
from typing import Collection

from parameterized import parameterized
Expand Down Expand Up @@ -81,7 +80,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.MISSING_PARAM, channel.json_body["errcode"])

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

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.UNKNOWN, channel.json_body["errcode"])

def _register_bg_update(self) -> None:
Expand Down Expand Up @@ -365,4 +364,4 @@ def test_start_backround_job_twice(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
15 changes: 7 additions & 8 deletions tests/rest/admin/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import urllib.parse
from http import HTTPStatus

from parameterized import parameterized

Expand Down Expand Up @@ -104,7 +103,7 @@ def test_user_does_not_exist(self, method: str) -> None:
@parameterized.expand(["GET", "PUT", "DELETE"])
def test_user_is_not_local(self, method: str) -> None:
"""
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
Tests that a lookup for a user that is not a local returns a 400
"""
url = (
"/_synapse/admin/v2/users/@unknown_person:unknown_domain/devices/%s"
Expand All @@ -117,7 +116,7 @@ def test_user_is_not_local(self, method: str) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only lookup local users", channel.json_body["error"])

def test_unknown_device(self) -> None:
Expand Down Expand Up @@ -179,7 +178,7 @@ def test_update_device_too_long_display_name(self) -> None:
content=update,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.TOO_LARGE, channel.json_body["errcode"])

# Ensure the display name was not updated.
Expand Down Expand Up @@ -353,7 +352,7 @@ def test_user_does_not_exist(self) -> None:

def test_user_is_not_local(self) -> None:
"""
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
Tests that a lookup for a user that is not a local returns a 400
"""
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/devices"

Expand All @@ -363,7 +362,7 @@ def test_user_is_not_local(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only lookup local users", channel.json_body["error"])

def test_user_has_no_devices(self) -> None:
Expand Down Expand Up @@ -479,7 +478,7 @@ def test_user_does_not_exist(self) -> None:

def test_user_is_not_local(self) -> None:
"""
Tests that a lookup for a user that is not a local returns a HTTPStatus.BAD_REQUEST
Tests that a lookup for a user that is not a local returns a 400
"""
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/delete_devices"

Expand All @@ -489,7 +488,7 @@ def test_user_is_not_local(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only lookup local users", channel.json_body["error"])

def test_unknown_devices(self) -> None:
Expand Down
21 changes: 10 additions & 11 deletions tests/rest/admin/test_event_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from http import HTTPStatus
from typing import List

from twisted.test.proto_helpers import MemoryReactor
Expand Down Expand Up @@ -278,7 +277,7 @@ def test_valid_search_order(self) -> None:

def test_invalid_search_order(self) -> None:
"""
Testing that a invalid search order returns a HTTPStatus.BAD_REQUEST
Testing that a invalid search order returns a 400
"""

channel = self.make_request(
Expand All @@ -288,7 +287,7 @@ def test_invalid_search_order(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -297,7 +296,7 @@ def test_invalid_search_order(self) -> None:

def test_limit_is_negative(self) -> None:
"""
Testing that a negative limit parameter returns a HTTPStatus.BAD_REQUEST
Testing that a negative limit parameter returns a 400
"""

channel = self.make_request(
Expand All @@ -307,15 +306,15 @@ def test_limit_is_negative(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

def test_from_is_negative(self) -> None:
"""
Testing that a negative from parameter returns a HTTPStatus.BAD_REQUEST
Testing that a negative from parameter returns a 400
"""

channel = self.make_request(
Expand All @@ -325,7 +324,7 @@ def test_from_is_negative(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand Down Expand Up @@ -507,7 +506,7 @@ def test_default_success(self) -> None:

def test_invalid_report_id(self) -> None:
"""
Testing that an invalid `report_id` returns a HTTPStatus.BAD_REQUEST.
Testing that an invalid `report_id` returns a 400.
"""

# `report_id` is negative
Expand All @@ -518,7 +517,7 @@ def test_invalid_report_id(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -536,7 +535,7 @@ def test_invalid_report_id(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -554,7 +553,7 @@ def test_invalid_report_id(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand Down
17 changes: 8 additions & 9 deletions tests/rest/admin/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from http import HTTPStatus
from typing import List, Optional

from parameterized import parameterized
Expand Down Expand Up @@ -77,7 +76,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# negative from
Expand All @@ -87,7 +86,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# unkown order_by
Expand All @@ -97,7 +96,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid search order
Expand All @@ -107,7 +106,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid destination
Expand Down Expand Up @@ -469,7 +468,7 @@ def test_destination_reset_connection_not_required(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(
"The retry timing does not need to be reset for this destination.",
channel.json_body["error"],
Expand Down Expand Up @@ -574,7 +573,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# negative from
Expand All @@ -584,7 +583,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid search order
Expand All @@ -594,7 +593,7 @@ def test_invalid_parameter(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])

# invalid destination
Expand Down
23 changes: 11 additions & 12 deletions tests/rest/admin/test_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from http import HTTPStatus

from parameterized import parameterized

Expand Down Expand Up @@ -105,7 +104,7 @@ def test_media_does_not_exist(self) -> None:

def test_media_is_not_local(self) -> None:
"""
Tests that a lookup for a media that is not a local returns a HTTPStatus.BAD_REQUEST
Tests that a lookup for a media that is not a local returns a 400
"""
url = "/_synapse/admin/v1/media/%s/%s" % ("unknown_domain", "12345")

Expand All @@ -115,7 +114,7 @@ def test_media_is_not_local(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only delete local media", channel.json_body["error"])

def test_delete_media(self) -> None:
Expand Down Expand Up @@ -259,7 +258,7 @@ def test_requester_is_no_admin(self) -> None:

def test_media_is_not_local(self) -> None:
"""
Tests that a lookup for media that is not local returns a HTTPStatus.BAD_REQUEST
Tests that a lookup for media that is not local returns a 400
"""
url = "/_synapse/admin/v1/media/%s/delete" % "unknown_domain"

Expand All @@ -269,7 +268,7 @@ def test_media_is_not_local(self) -> None:
access_token=self.admin_user_tok,
)

self.assertEqual(HTTPStatus.BAD_REQUEST, channel.code, msg=channel.json_body)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual("Can only delete local media", channel.json_body["error"])

def test_missing_parameter(self) -> None:
Expand All @@ -283,7 +282,7 @@ def test_missing_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -303,7 +302,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -320,7 +319,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -338,7 +337,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -355,7 +354,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand Down Expand Up @@ -931,7 +930,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand All @@ -948,7 +947,7 @@ def test_invalid_parameter(self) -> None:
)

self.assertEqual(
HTTPStatus.BAD_REQUEST,
400,
channel.code,
msg=channel.json_body,
)
Expand Down
Loading