mirror of
https://github.com/zulip/zulip.git
synced 2025-11-23 16:01:24 +00:00
Remove callback logic from test_helpers.DummyHandler.
This commit is contained in:
@@ -194,28 +194,11 @@ class DummyTornadoRequest(object):
|
|||||||
self.connection.stream = DummyStream() # type: ignore # monkey-patching here
|
self.connection.stream = DummyStream() # type: ignore # monkey-patching here
|
||||||
|
|
||||||
class DummyHandler(object):
|
class DummyHandler(object):
|
||||||
def __init__(self, assert_callback):
|
def __init__(self):
|
||||||
# type: (Callable) -> None
|
# type: (Callable) -> None
|
||||||
self.assert_callback = assert_callback
|
|
||||||
self.request = DummyTornadoRequest()
|
self.request = DummyTornadoRequest()
|
||||||
allocate_handler_id(self)
|
allocate_handler_id(self)
|
||||||
|
|
||||||
# Mocks RequestHandler.async_callback, which wraps a callback to
|
|
||||||
# handle exceptions. We return the callback as-is.
|
|
||||||
def async_callback(self, cb):
|
|
||||||
# type: (Callable) -> Callable
|
|
||||||
return cb
|
|
||||||
|
|
||||||
def write(self, response):
|
|
||||||
# type: (str) -> None
|
|
||||||
raise NotImplemented
|
|
||||||
|
|
||||||
def zulip_finish(self, response, *ignore):
|
|
||||||
# type: (HttpResponse, *Any) -> None
|
|
||||||
if self.assert_callback:
|
|
||||||
self.assert_callback(response)
|
|
||||||
|
|
||||||
|
|
||||||
class DummySession(object):
|
class DummySession(object):
|
||||||
session_key = "0"
|
session_key = "0"
|
||||||
|
|
||||||
@@ -227,11 +210,11 @@ class DummyStream(object):
|
|||||||
class POSTRequestMock(object):
|
class POSTRequestMock(object):
|
||||||
method = "POST"
|
method = "POST"
|
||||||
|
|
||||||
def __init__(self, post_data, user_profile, assert_callback=None):
|
def __init__(self, post_data, user_profile):
|
||||||
# type: (Dict[str, Any], UserProfile, Optional[Callable]) -> None
|
# type: (Dict[str, Any], UserProfile) -> None
|
||||||
self.REQUEST = self.POST = post_data
|
self.REQUEST = self.POST = post_data
|
||||||
self.user = user_profile
|
self.user = user_profile
|
||||||
self._tornado_handler = DummyHandler(assert_callback)
|
self._tornado_handler = DummyHandler()
|
||||||
self.session = DummySession()
|
self.session = DummySession()
|
||||||
self._log_data = {} # type: Dict[str, Any]
|
self._log_data = {} # type: Dict[str, Any]
|
||||||
self.META = {'PATH_INFO': 'test'}
|
self.META = {'PATH_INFO': 'test'}
|
||||||
|
|||||||
@@ -66,10 +66,9 @@ from six.moves import range
|
|||||||
|
|
||||||
|
|
||||||
class GetEventsTest(AuthedTestCase):
|
class GetEventsTest(AuthedTestCase):
|
||||||
def tornado_call(self, view_func, user_profile, post_data,
|
def tornado_call(self, view_func, user_profile, post_data):
|
||||||
callback=None):
|
# type: (Callable[[HttpRequest, UserProfile], HttpResponse], UserProfile, Dict[str, Any]) -> HttpResponse
|
||||||
# type: (Callable[[HttpRequest, UserProfile], HttpResponse], UserProfile, Dict[str, Any], Optional[Callable]) -> HttpResponse
|
request = POSTRequestMock(post_data, user_profile)
|
||||||
request = POSTRequestMock(post_data, user_profile, callback)
|
|
||||||
return view_func(request, user_profile)
|
return view_func(request, user_profile)
|
||||||
|
|
||||||
def test_get_events(self):
|
def test_get_events(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user