Use literals in place of HTTPStatus constants in tests (#13463)

This commit is contained in:
Dirk Klimpel 2022-08-05 16:59:09 +02:00 committed by GitHub
parent 3d2cabf966
commit e2ed1b7155
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 172 additions and 191 deletions

View file

@ -104,7 +104,7 @@ class JsonResourceTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
)
self.assertEqual(channel.result["code"], b"500")
self.assertEqual(channel.code, 500)
def test_callback_indirect_exception(self) -> None:
"""
@ -130,7 +130,7 @@ class JsonResourceTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
)
self.assertEqual(channel.result["code"], b"500")
self.assertEqual(channel.code, 500)
def test_callback_synapseerror(self) -> None:
"""
@ -150,7 +150,7 @@ class JsonResourceTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foo"
)
self.assertEqual(channel.result["code"], b"403")
self.assertEqual(channel.code, 403)
self.assertEqual(channel.json_body["error"], "Forbidden!!one!")
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
@ -174,7 +174,7 @@ class JsonResourceTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/_matrix/foobar"
)
self.assertEqual(channel.result["code"], b"400")
self.assertEqual(channel.code, 400)
self.assertEqual(channel.json_body["error"], "Unrecognized request")
self.assertEqual(channel.json_body["errcode"], "M_UNRECOGNIZED")
@ -203,7 +203,7 @@ class JsonResourceTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"HEAD", b"/_matrix/foo"
)
self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
self.assertNotIn("body", channel.result)
@ -242,7 +242,7 @@ class OptionsResourceTests(unittest.TestCase):
def test_unknown_options_request(self) -> None:
"""An OPTIONS requests to an unknown URL still returns 204 No Content."""
channel = self._make_request(b"OPTIONS", b"/foo/")
self.assertEqual(channel.result["code"], b"204")
self.assertEqual(channel.code, 204)
self.assertNotIn("body", channel.result)
# Ensure the correct CORS headers have been added
@ -262,7 +262,7 @@ class OptionsResourceTests(unittest.TestCase):
def test_known_options_request(self) -> None:
"""An OPTIONS requests to an known URL still returns 204 No Content."""
channel = self._make_request(b"OPTIONS", b"/res/")
self.assertEqual(channel.result["code"], b"204")
self.assertEqual(channel.code, 204)
self.assertNotIn("body", channel.result)
# Ensure the correct CORS headers have been added
@ -282,12 +282,12 @@ class OptionsResourceTests(unittest.TestCase):
def test_unknown_request(self) -> None:
"""A non-OPTIONS request to an unknown URL should 404."""
channel = self._make_request(b"GET", b"/foo/")
self.assertEqual(channel.result["code"], b"404")
self.assertEqual(channel.code, 404)
def test_known_request(self) -> None:
"""A non-OPTIONS request to an known URL should query the proper resource."""
channel = self._make_request(b"GET", b"/res/")
self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
self.assertEqual(channel.result["body"], b"/res/")
@ -314,7 +314,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
)
self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
body = channel.result["body"]
self.assertEqual(body, b"response")
@ -334,7 +334,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
)
self.assertEqual(channel.result["code"], b"301")
self.assertEqual(channel.code, 301)
headers = channel.result["headers"]
location_headers = [v for k, v in headers if k == b"Location"]
self.assertEqual(location_headers, [b"/look/an/eagle"])
@ -357,7 +357,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"GET", b"/path"
)
self.assertEqual(channel.result["code"], b"304")
self.assertEqual(channel.code, 304)
headers = channel.result["headers"]
location_headers = [v for k, v in headers if k == b"Location"]
self.assertEqual(location_headers, [b"/no/over/there"])
@ -378,7 +378,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
self.reactor, FakeSite(res, self.reactor), b"HEAD", b"/path"
)
self.assertEqual(channel.result["code"], b"200")
self.assertEqual(channel.code, 200)
self.assertNotIn("body", channel.result)