mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
webhook tests: Require args for check_webhook.
We tighten up the mypy types here. And then once we know that expected_message and expected_topic are never None, we don't have call the do_test_message and do_test_topic helpers any more, so we eliminate them, too. Finally, we don't return a message, since no tests use the message currently.
This commit is contained in:
@@ -1029,11 +1029,11 @@ class WebhookTestCase(ZulipTestCase):
|
|||||||
def check_webhook(
|
def check_webhook(
|
||||||
self,
|
self,
|
||||||
fixture_name: str,
|
fixture_name: str,
|
||||||
expected_topic: Optional[str]=None,
|
expected_topic: str,
|
||||||
expected_message: Optional[str]=None,
|
expected_message: str,
|
||||||
content_type: Optional[str]="application/json",
|
content_type: Optional[str]="application/json",
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Message:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
check_webhook is the main way to test "normal" webhooks that
|
check_webhook is the main way to test "normal" webhooks that
|
||||||
work by receiving a payload from a third party and then writing
|
work by receiving a payload from a third party and then writing
|
||||||
@@ -1069,11 +1069,13 @@ class WebhookTestCase(ZulipTestCase):
|
|||||||
payload,
|
payload,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
self.assertEqual(get_display_recipient(msg.recipient), self.STREAM_NAME)
|
|
||||||
self.do_test_topic(msg, expected_topic)
|
|
||||||
self.do_test_message(msg, expected_message)
|
|
||||||
|
|
||||||
return msg
|
self.assert_stream_message(
|
||||||
|
message=msg,
|
||||||
|
stream_name=self.STREAM_NAME,
|
||||||
|
topic_name=expected_topic,
|
||||||
|
content=expected_message,
|
||||||
|
)
|
||||||
|
|
||||||
def assert_stream_message(
|
def assert_stream_message(
|
||||||
self,
|
self,
|
||||||
@@ -1149,14 +1151,6 @@ class WebhookTestCase(ZulipTestCase):
|
|||||||
assert self.FIXTURE_DIR_NAME is not None
|
assert self.FIXTURE_DIR_NAME is not None
|
||||||
return orjson.dumps(orjson.loads(self.webhook_fixture_data(self.FIXTURE_DIR_NAME, fixture_name))).decode()
|
return orjson.dumps(orjson.loads(self.webhook_fixture_data(self.FIXTURE_DIR_NAME, fixture_name))).decode()
|
||||||
|
|
||||||
def do_test_topic(self, msg: Message, expected_topic: Optional[str]) -> None:
|
|
||||||
if expected_topic is not None:
|
|
||||||
self.assertEqual(msg.topic_name(), expected_topic)
|
|
||||||
|
|
||||||
def do_test_message(self, msg: Message, expected_message: Optional[str]) -> None:
|
|
||||||
if expected_message is not None:
|
|
||||||
self.assertEqual(msg.content, expected_message)
|
|
||||||
|
|
||||||
class MigrationsTestCase(ZulipTestCase): # nocoverage
|
class MigrationsTestCase(ZulipTestCase): # nocoverage
|
||||||
"""
|
"""
|
||||||
Test class for database migrations inspired by this blog post:
|
Test class for database migrations inspired by this blog post:
|
||||||
|
|||||||
Reference in New Issue
Block a user