Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Update event tests for `do_update_message` action.
Lauryn Menard93210954065d
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex 84fd284084a..f80d18b5d43 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -1523,22 +1523,14 @@ update_message_required_fields = [("user_id", int),("edit_timestamp", int),("message_id", int),-]--update_message_content_fields: List[Tuple[str, object]] = [- ("content", str),- ("is_me_message", bool),- ("orig_content", str),- ("orig_rendered_content", str),- ("prev_rendered_content_version", int),- ("rendered_content", str),-]--update_message_topic_fields = [("flags", ListType(str)),("message_ids", ListType(int)),+]++update_message_stream_fields: List[Tuple[str, object]] = [+ ("stream_id", int),+ ("stream_name", str),("new_stream_id", int),- (ORIG_TOPIC, str),("propagate_mode",EnumType(@@ -1550,13 +1542,26 @@ update_message_topic_fields = []),),- ("stream_id", int),- ("stream_name", str),+ (ORIG_TOPIC, str),+]++update_message_content_fields: List[Tuple[str, object]] = [+ ("content", str),+ ("is_me_message", bool),+ ("orig_content", str),+ ("orig_rendered_content", str),+ ("prev_rendered_content_version", int),+ ("rendered_content", str),+]++update_message_topic_fields = [(TOPIC_LINKS, ListType(_check_topic_links)),(TOPIC_NAME, str),]-update_message_optional_fields = update_message_content_fields + update_message_topic_fields+update_message_optional_fields = (+ update_message_stream_fields + update_message_content_fields + update_message_topic_fields+)# The schema here does not include the "embedded"# variant of update_message; it is for message@@ -1571,6 +1576,7 @@ _check_update_message = make_checker(update_message_event)def check_update_message(var_name: str,event: Dict[str, object],+ is_stream_message: bool,has_content: bool,has_topic: bool,has_new_stream_id: bool,@@ -1582,6 +1588,9 @@ def check_update_message(expected_keys = {"id"}expected_keys.update(tup[0] for tup in update_message_required_fields)+ if is_stream_message:+ expected_keys.update(tup[0] for tup in update_message_stream_fields)+if has_content:expected_keys.update(tup[0] for tup in update_message_content_fields)@@ -1591,6 +1600,10 @@ def check_update_message(if not has_new_stream_id:expected_keys.discard("new_stream_id")+ if not has_new_stream_id and not has_topic:+ expected_keys.discard("propagate_mode")+ expected_keys.discard(ORIG_TOPIC)+assert expected_keys == actual_keysdiff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex f8cdca659f1..bcd83b4d65d 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -432,6 +432,41 @@ class NormalActionsTest(BaseAction):),)+ # Verify private message editing - content only edit+ pm = Message.objects.order_by("-id")[0]+ content = "new content"+ rendering_result = render_markdown(pm, content)+ prior_mention_user_ids: Set[int] = set()+ mention_data = MentionData(+ realm_id=self.user_profile.realm_id,+ content=content,+ )++ events = self.verify_action(+ lambda: do_update_message(+ self.user_profile,+ pm,+ None,+ None,+ None,+ False,+ False,+ content,+ rendering_result,+ prior_mention_user_ids,+ mention_data,+ ),+ state_change_expected=False,+ )+ check_update_message(+ "events[0]",+ events[0],+ is_stream_message=False,+ has_content=True,+ has_topic=False,+ has_new_stream_id=False,+ )+def test_huddle_send_message_events(self) -> None:huddle = [self.example_user("hamlet"),@@ -456,10 +491,8 @@ class NormalActionsTest(BaseAction):check_message("events[0]", events[0])assert events[0]["message"]["avatar_url"] is None- # Verify message editing+ # Verify stream message editing - content onlymessage = Message.objects.order_by("-id")[0]- topic = "new_topic"- propagate_mode = "change_all"content = "new content"rendering_result = render_markdown(message, content)prior_mention_user_ids: Set[int] = set()@@ -473,8 +506,8 @@ class NormalActionsTest(BaseAction):self.user_profile,message,None,- topic,- propagate_mode,+ None,+ None,False,False,content,@@ -482,12 +515,42 @@ class NormalActionsTest(BaseAction):prior_mention_user_ids,mention_data,),- state_change_expected=True,+ state_change_expected=False,)check_update_message("events[0]",events[0],+ is_stream_message=True,has_content=True,+ has_topic=False,+ has_new_stream_id=False,+ )++ # Verify stream message editing - topic only+ topic = "new_topic"+ propagate_mode = "change_all"++ events = self.verify_action(+ lambda: do_update_message(+ self.user_profile,+ message,+ None,+ topic,+ propagate_mode,+ False,+ False,+ None,+ None,+ prior_mention_user_ids,+ mention_data,+ ),+ state_change_expected=True,+ )+ check_update_message(+ "events[0]",+ events[0],+ is_stream_message=True,+ has_content=False,has_topic=True,has_new_stream_id=False,)@@ -506,7 +569,6 @@ class NormalActionsTest(BaseAction):self.send_stream_message(self.user_profile, "Verona")message_id = self.send_stream_message(self.user_profile, "Verona")message = Message.objects.get(id=message_id)- topic = "new_topic"stream = get_stream("Denmark", self.user_profile.realm)propagate_mode = "change_all"prior_mention_user_ids = set()@@ -516,7 +578,7 @@ class NormalActionsTest(BaseAction):self.user_profile,message,stream,- topic,+ None,propagate_mode,True,True,@@ -534,8 +596,9 @@ class NormalActionsTest(BaseAction):check_update_message("events[0]",events[0],+ is_stream_message=True,has_content=False,- has_topic=True,+ has_topic=False,has_new_stream_id=True,)