mirror of https://github.com/zulip/zulip.git
tests: Add test for /poll message.
This goes through the /messages endpoint to get more full-stack testing, and it focuses on how SubMessage rows get created.
This commit is contained in:
parent
383567aa73
commit
922b1683fc
|
@ -2,6 +2,8 @@ import ujson
|
|||
|
||||
from typing import Dict, Any
|
||||
|
||||
from zerver.models import SubMessage
|
||||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
|
||||
from zerver.lib.validator import check_widget_content
|
||||
|
@ -78,3 +80,62 @@ class WidgetContentTestCase(ZulipTestCase):
|
|||
payload['widget_content'] = ujson.dumps(bogus_data)
|
||||
result = self.api_post(sender_email, "/api/v1/messages", payload)
|
||||
self.assert_json_error_contains(result, 'Widgets: widget_type is not in widget_content')
|
||||
|
||||
def test_poll_command_extra_data(self) -> None:
|
||||
sender_email = self.example_email('cordelia')
|
||||
stream_name = 'Verona'
|
||||
content = '/poll What is your favorite color?'
|
||||
|
||||
payload = dict(
|
||||
type="stream",
|
||||
to=stream_name,
|
||||
sender=sender_email,
|
||||
client='test suite',
|
||||
subject='whatever',
|
||||
content=content,
|
||||
)
|
||||
result = self.api_post(sender_email, "/api/v1/messages", payload)
|
||||
self.assert_json_success(result)
|
||||
|
||||
message = self.get_last_message()
|
||||
self.assertEqual(message.content, content)
|
||||
|
||||
expected_submessage_content = dict(
|
||||
widget_type="poll",
|
||||
extra_data=dict(
|
||||
question="What is your favorite color?",
|
||||
),
|
||||
)
|
||||
|
||||
submessage = SubMessage.objects.get(message_id=message.id)
|
||||
self.assertEqual(submessage.msg_type, 'widget')
|
||||
self.assertEqual(ujson.loads(submessage.content), expected_submessage_content)
|
||||
|
||||
# Now don't supply a question.
|
||||
|
||||
content = '/poll'
|
||||
payload['content'] = content
|
||||
result = self.api_post(sender_email, "/api/v1/messages", payload)
|
||||
self.assert_json_success(result)
|
||||
|
||||
expected_submessage_content = dict(
|
||||
widget_type="poll",
|
||||
extra_data=dict(
|
||||
question="",
|
||||
),
|
||||
)
|
||||
|
||||
message = self.get_last_message()
|
||||
self.assertEqual(message.content, content)
|
||||
submessage = SubMessage.objects.get(message_id=message.id)
|
||||
self.assertEqual(submessage.msg_type, 'widget')
|
||||
self.assertEqual(ujson.loads(submessage.content), expected_submessage_content)
|
||||
|
||||
# Now test the feature flag.
|
||||
with self.settings(ALLOW_SUB_MESSAGES=False):
|
||||
result = self.api_post(sender_email, "/api/v1/messages", payload)
|
||||
self.assert_json_success(result)
|
||||
|
||||
message = self.get_last_message()
|
||||
self.assertEqual(message.content, content)
|
||||
self.assertFalse(SubMessage.objects.filter(message_id=message.id).exists())
|
||||
|
|
Loading…
Reference in New Issue