Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_helpers: Remove unnecessary HostRequestMock.body override.
Anders Kaseorge245f5197415
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex dbd192b5768..29a876041dd 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -372,14 +372,6 @@ class HostRequestMock(HttpRequest):),)- @property- def body(self) -> bytes:- return super().body-- @body.setter- def body(self, val: bytes) -> None:- self._body = val-def get_host(self) -> str:return self.hostdiff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex d81d7070163..be470db21cd 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -200,7 +200,7 @@ class DecoratorTestCase(ZulipTestCase):request.POST["api_key"] = webhook_bot_api_keywith self.assertLogs("zulip.zerver.webhooks", level="INFO") as log:with self.assertRaisesRegex(Exception, "raised by webhook function"):- request.body = b"{}"+ request._body = b"{}"request.content_type = "application/json"my_webhook_raises_exception(request)@@ -212,7 +212,7 @@ class DecoratorTestCase(ZulipTestCase):request.POST["api_key"] = webhook_bot_api_keywith self.assertLogs("zulip.zerver.webhooks", level="INFO") as log:with self.assertRaisesRegex(Exception, "raised by webhook function"):- request.body = b"notjson"+ request._body = b"notjson"request.content_type = "text/plain"my_webhook_raises_exception(request)@@ -224,7 +224,7 @@ class DecoratorTestCase(ZulipTestCase):request.POST["api_key"] = webhook_bot_api_keywith self.assertLogs("zulip.zerver.webhooks", level="ERROR") as log:with self.assertRaisesRegex(Exception, "raised by webhook function"):- request.body = b"invalidjson"+ request._body = b"invalidjson"request.content_type = "application/json"request.META["HTTP_X_CUSTOM_HEADER"] = "custom_value"my_webhook_raises_exception(request)@@ -242,7 +242,7 @@ class DecoratorTestCase(ZulipTestCase):)with self.assertLogs("zulip.zerver.webhooks.unsupported", level="ERROR") as log:with self.assertRaisesRegex(UnsupportedWebhookEventTypeError, exception_msg):- request.body = b"invalidjson"+ request._body = b"invalidjson"request.content_type = "application/json"request.META["HTTP_X_CUSTOM_HEADER"] = "custom_value"my_webhook_raises_exception_unsupported_event(request)@@ -381,7 +381,7 @@ class DecoratorLoggingTestCase(ZulipTestCase):request.method = "POST"request.host = "zulip.testserver"- request.body = b"{}"+ request._body = b"{}"request.content_type = "text/plain"with self.assertLogs("zulip.zerver.webhooks") as logger:@@ -404,7 +404,7 @@ class DecoratorLoggingTestCase(ZulipTestCase):request.method = "POST"request.host = "zulip.testserver"- request.body = b"{}"+ request._body = b"{}"request.content_type = "text/plain"with mock.patch(@@ -432,7 +432,7 @@ class DecoratorLoggingTestCase(ZulipTestCase):request.method = "POST"request.host = "zulip.testserver"- request.body = b"{}"+ request._body = b"{}"request.content_type = "application/json"with mock.patch("zerver.decorator.webhook_logger.exception") as mock_exception:diff --git a/zerver/tests/test_has_request_variables.py b/zerver/tests/test_has_request_variables.pyindex cb2b51454aa..47692357a10 100644--- a/zerver/tests/test_has_request_variables.py+++ b/zerver/tests/test_has_request_variables.py@@ -140,18 +140,18 @@ class REQTestCase(ZulipTestCase):return json_response(data={"payload": payload})request = HostRequestMock()- request.body = b"\xde\xad\xbe\xef"+ request._body = b"\xde\xad\xbe\xef"with self.assertRaises(JsonableError) as cm:get_payload(request)self.assertEqual(str(cm.exception), "Malformed payload")request = HostRequestMock()- request.body = b"notjson"+ request._body = b"notjson"with self.assertRaises(JsonableError) as cm:get_payload(request)self.assertEqual(str(cm.exception), "Malformed JSON")- request.body = b'{"a": "b"}'+ request._body = b'{"a": "b"}'self.assertEqual(orjson.loads(get_payload(request).content).get("payload"), {"a": "b"})diff --git a/zerver/tests/test_typed_endpoint.py b/zerver/tests/test_typed_endpoint.pyindex c89007fe5c7..d902482f3e0 100644--- a/zerver/tests/test_typed_endpoint.py+++ b/zerver/tests/test_typed_endpoint.py@@ -262,26 +262,26 @@ class TestEndpoint(ZulipTestCase):# Set the body manually so that we can pass in something unusualrequest = HostRequestMock()- request.body = orjson.dumps([])+ request._body = orjson.dumps([])with self.assertRaisesRegex(DjangoValidationError, "request is not a dict"):result = call_endpoint(webhook, request)# Test for the rare case when both body and GET are usedrequest = HostRequestMock()request.GET.update({"non_body": "15"})- request.body = orjson.dumps({"totame": {"status": True}})+ request._body = orjson.dumps({"totame": {"status": True}})result = call_endpoint(webhook, request)self.assertDictEqual(result, {"status": True, "foo": 15})with self.assertRaisesMessage(JsonableError, "Malformed JSON"):request = HostRequestMock()- request.body = b"{malformed_json"+ request._body = b"{malformed_json"call_endpoint(webhook, request)with self.assertRaisesMessage(JsonableError, "Malformed payload"):request = HostRequestMock()# This body triggers UnicodeDecodeError- request.body = b"\x81"+ request._body = b"\x81"call_endpoint(webhook, request)def test_path_only(self) -> None: