Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_helpers: Remove default tornado_handler from HostRequestMock.
Anders Kaseorg952422d373c5
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex 051b3ed6ed1..8dd47a63ef0 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -291,6 +291,9 @@ class DummyHandler(AsyncDjangoHandler):allocate_handler_id(self)+dummy_handler = DummyHandler()++class HostRequestMock(HttpRequest):"""A mock request object where get_host() works. Useful for testingroutes that use Zulip's subdomains feature"""@@ -302,7 +305,7 @@ class HostRequestMock(HttpRequest):host: str = settings.EXTERNAL_HOST,client_name: Optional[str] = None,meta_data: Optional[Dict[str, Any]] = None,- tornado_handler: Optional[AsyncDjangoHandler] = DummyHandler(),+ tornado_handler: Optional[AsyncDjangoHandler] = None,path: str = "",) -> None:self.host = hostdiff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex d4d800f10f2..f1883decce6 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -56,7 +56,7 @@ from zerver.lib.request import ()from zerver.lib.response import json_response, json_successfrom zerver.lib.test_classes import ZulipTestCase-from zerver.lib.test_helpers import DummyHandler, HostRequestMock+from zerver.lib.test_helpers import HostRequestMock, dummy_handlerfrom zerver.lib.types import Validatorfrom zerver.lib.user_agent import parse_user_agentfrom zerver.lib.users import get_api_key@@ -1550,7 +1550,6 @@ class TestInternalNotifyView(ZulipTestCase):request = HostRequestMock(post_data=dict(secret=secret),meta_data=dict(REMOTE_ADDR="127.0.0.1"),- tornado_handler=None,)with self.settings(SHARED_SECRET=secret):@@ -1567,9 +1566,8 @@ class TestInternalNotifyView(ZulipTestCase):request = HostRequestMock(post_data=dict(secret=secret),meta_data=dict(REMOTE_ADDR="127.0.0.1"),- tornado_handler=None,+ tornado_handler=dummy_handler,)- RequestNotes.get_notes(request).tornado_handler = DummyHandler()with self.settings(SHARED_SECRET=secret):self.assertTrue(authenticate_notify(request))self.assertEqual(diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.pyindex 0b374dc98ee..0f21f1cc426 100644--- a/zerver/tests/test_event_queue.py+++ b/zerver/tests/test_event_queue.py@@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponsefrom zerver.actions.streams import do_change_subscription_propertyfrom zerver.actions.user_topics import do_mute_topicfrom zerver.lib.test_classes import ZulipTestCase-from zerver.lib.test_helpers import HostRequestMock, mock_queue_publish+from zerver.lib.test_helpers import HostRequestMock, dummy_handler, mock_queue_publishfrom zerver.lib.user_groups import create_user_group, remove_user_from_user_groupfrom zerver.models import Recipient, Stream, Subscription, UserProfile, get_streamfrom zerver.tornado.event_queue import (@@ -84,7 +84,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):user_profile: UserProfile,post_data: Dict[str, Any],) -> HttpResponse:- request = HostRequestMock(post_data, user_profile)+ request = HostRequestMock(post_data, user_profile, tornado_handler=dummy_handler)return view_func(request, user_profile)def test_stream_watchers(self) -> None:diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex c27d8afa851..22155a0da12 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -16,7 +16,12 @@ from zerver.lib.event_schema import check_restart_eventfrom zerver.lib.events import fetch_initial_state_datafrom zerver.lib.exceptions import AccessDeniedErrorfrom zerver.lib.test_classes import ZulipTestCase-from zerver.lib.test_helpers import HostRequestMock, queries_captured, stub_event_queue_user_events+from zerver.lib.test_helpers import (+ HostRequestMock,+ dummy_handler,+ queries_captured,+ stub_event_queue_user_events,+)from zerver.lib.users import get_api_key, get_raw_user_datafrom zerver.models import (Realm,@@ -207,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)+ req = HostRequestMock(post_data, user_profile=None, 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)@@ -220,7 +225,7 @@ class GetEventsTest(ZulipTestCase):user_profile: UserProfile,post_data: Dict[str, Any],) -> HttpResponse:- request = HostRequestMock(post_data, user_profile)+ request = HostRequestMock(post_data, user_profile, tornado_handler=dummy_handler)return view_func(request, user_profile)def test_get_events(self) -> None:@@ -896,7 +901,9 @@ class RestartEventsTest(ZulipTestCase):post_data: Dict[str, Any],client_name: Optional[str] = None,) -> HttpResponse:- request = HostRequestMock(post_data, user_profile, client_name=client_name)+ request = HostRequestMock(+ post_data, user_profile, client_name=client_name, tornado_handler=dummy_handler+ )return view_func(request, user_profile)def test_restart(self) -> None: