mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-19 06:24:07 -04:00
Use literals in place of HTTPStatus
constants in tests (#13488)
* Use literals in place of `HTTPStatus` constants in tests * newsfile * code style * code style
This commit is contained in:
parent
51c01d450a
commit
2281427175
12 changed files with 177 additions and 447 deletions
|
@ -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
|
||||
|
@ -81,11 +80,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
"""
|
||||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
self.assertEqual(401, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
|
@ -99,11 +94,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
403,
|
||||
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_default_success(self) -> None:
|
||||
|
@ -278,7 +269,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
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(
|
||||
|
@ -287,17 +278,13 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
self.assertEqual("Unknown direction: bar", channel.json_body["error"])
|
||||
|
||||
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(
|
||||
|
@ -306,16 +293,12 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
|
||||
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(
|
||||
|
@ -324,11 +307,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
|
||||
def test_next_token(self) -> None:
|
||||
|
@ -466,11 +445,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
"""
|
||||
channel = self.make_request("GET", self.url, b"{}")
|
||||
|
||||
self.assertEqual(
|
||||
401,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
self.assertEqual(401, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||
|
||||
def test_requester_is_no_admin(self) -> None:
|
||||
|
@ -484,11 +459,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.other_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
403,
|
||||
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_default_success(self) -> None:
|
||||
|
@ -507,7 +478,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
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
|
||||
|
@ -517,11 +488,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
self.assertEqual(
|
||||
"The report_id parameter must be a string representing a positive integer.",
|
||||
|
@ -535,11 +502,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
self.assertEqual(
|
||||
"The report_id parameter must be a string representing a positive integer.",
|
||||
|
@ -553,11 +516,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
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"])
|
||||
self.assertEqual(
|
||||
"The report_id parameter must be a string representing a positive integer.",
|
||||
|
@ -575,11 +534,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
|||
access_token=self.admin_user_tok,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
404,
|
||||
channel.code,
|
||||
msg=channel.json_body,
|
||||
)
|
||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||
self.assertEqual("Event report not found", channel.json_body["error"])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue