Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_helpers: Default user_profile to AnonymousUser.
Zixuan James Li0056becd0480
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex b5054a6fd22..69c181980f9 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -300,7 +300,7 @@ class HostRequestMock(HttpRequest):def __init__(self,post_data: Dict[str, Any] = {},- user_profile: Optional[Union[UserProfile, AnonymousUser, RemoteZulipServer]] = None,+ user_profile: Union[UserProfile, RemoteZulipServer, None] = None,host: str = settings.EXTERNAL_HOST,client_name: Optional[str] = None,meta_data: Optional[Dict[str, Any]] = None,@@ -325,7 +325,7 @@ class HostRequestMock(HttpRequest):else:self.META = meta_dataself.path = path- self.user = user_profile+ self.user = user_profile or AnonymousUser()self._body = b""self.content_type = ""BaseNotes[str, str].get_notesdiff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex 1c59a2f29c4..66b3c399365 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -650,9 +650,8 @@ class RateLimitTestCase(ZulipTestCase):def test_internal_local_clients_skip_rate_limiting(self) -> None:META = {"REMOTE_ADDR": "127.0.0.1"}- user = AnonymousUser()- request = HostRequestMock(client_name="internal", user_profile=user, meta_data=META)+ request = HostRequestMock(client_name="internal", meta_data=META)f = self.get_ratelimited_view()@@ -668,9 +667,8 @@ class RateLimitTestCase(ZulipTestCase):def test_debug_clients_skip_rate_limiting(self) -> None:META = {"REMOTE_ADDR": "3.3.3.3"}- user = AnonymousUser()- req = HostRequestMock(client_name="internal", user_profile=user, meta_data=META)+ req = HostRequestMock(client_name="internal", meta_data=META)f = self.get_ratelimited_view()@@ -742,9 +740,8 @@ class RateLimitTestCase(ZulipTestCase):def test_rate_limiting_happens_by_ip_if_unauthed(self) -> None:META = {"REMOTE_ADDR": "3.3.3.3"}- user = AnonymousUser()- req = HostRequestMock(client_name="external", user_profile=user, meta_data=META)+ req = HostRequestMock(client_name="external", meta_data=META)f = self.get_ratelimited_view()diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex 22155a0da12..959ec832d2f 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -204,7 +204,7 @@ class EventsEndpointTest(ZulipTestCase):),).decode(),)- req = HostRequestMock(post_data, user_profile=None)+ req = HostRequestMock(post_data)req.META["REMOTE_ADDR"] = "127.0.0.1"with self.assertRaises(AccessDeniedError) as context:result = self.client_post_request("/notify_tornado", req)@@ -212,7 +212,7 @@ class EventsEndpointTest(ZulipTestCase):self.assertEqual(context.exception.http_status_code, 403)post_data["secret"] = settings.SHARED_SECRET- req = HostRequestMock(post_data, user_profile=None, tornado_handler=dummy_handler)+ req = HostRequestMock(post_data, tornado_handler=dummy_handler)req.META["REMOTE_ADDR"] = "127.0.0.1"result = self.client_post_request("/notify_tornado", req)self.assert_json_success(result)