Ejemplo n.º 1
0
    def test_archiving_message_with_reactions(self) -> None:
        msg_id = self.send_stream_message(self.sender, "Verona")

        for name in ["hamlet", "cordelia"]:
            self.api_post(
                self.example_user(name),
                f"/api/v1/messages/{msg_id}/reactions",
                zulip_reaction_info(),
            )

        reaction_ids = list(
            Reaction.objects.filter(message_id=msg_id).values_list(
                "id", flat=True), )

        self.assertEqual(
            Reaction.objects.filter(id__in=reaction_ids).count(), 2)
        move_messages_to_archive(message_ids=[msg_id])

        self.assertEqual(
            set(
                ArchivedReaction.objects.filter(message_id=msg_id).values_list(
                    "id", flat=True)),
            set(reaction_ids),
        )
        self.assertEqual(
            Reaction.objects.filter(id__in=reaction_ids).count(), 0)

        restore_all_data_from_archive()
        self.assertEqual(
            set(
                Reaction.objects.filter(id__in=reaction_ids).values_list(
                    "id", flat=True)),
            set(reaction_ids),
        )
Ejemplo n.º 2
0
    def test_archiving_reactions(self) -> None:
        expired_msg_ids = self._make_expired_zulip_messages(2)

        hamlet = self.example_user("hamlet")
        cordelia = self.example_user("cordelia")

        for sender in [hamlet, cordelia]:
            self.api_post(
                sender,
                f"/api/v1/messages/{expired_msg_ids[0]}/reactions",
                zulip_reaction_info(),
            )

        self.api_post(
            hamlet,
            f"/api/v1/messages/{expired_msg_ids[1]}/reactions",
            zulip_reaction_info(),
        )

        reaction_ids = list(
            Reaction.objects.filter(
                message_id__in=expired_msg_ids).values_list("id", flat=True), )

        self.assert_length(reaction_ids, 3)
        self.assertEqual(
            Reaction.objects.filter(id__in=reaction_ids).count(), 3)
        archive_messages()
        self.assertEqual(
            Reaction.objects.filter(id__in=reaction_ids).count(), 0)

        self.assertEqual(
            set(
                ArchivedReaction.objects.filter(
                    id__in=reaction_ids).values_list("id", flat=True)),
            set(reaction_ids),
        )

        restore_all_data_from_archive()
        self.assertEqual(
            set(
                Reaction.objects.filter(id__in=reaction_ids).values_list(
                    "id", flat=True)),
            set(reaction_ids),
        )
Ejemplo n.º 3
0
 def test_delete_non_existent_zulip_reaction(self) -> None:
     result = self.delete_reaction(zulip_reaction_info())
     self.assert_json_error(result, "Reaction doesn't exist.")
Ejemplo n.º 4
0
    def test_delete_zulip_emoji(self) -> None:
        result = self.post_reaction(zulip_reaction_info())
        self.assert_json_success(result)

        result = self.delete_reaction(zulip_reaction_info())
        self.assert_json_success(result)
Ejemplo n.º 5
0
    def test_add_duplicate_zulip_reaction(self) -> None:
        result = self.post_reaction(zulip_reaction_info())
        self.assert_json_success(result)

        result = self.post_reaction(zulip_reaction_info())
        self.assert_json_error(result, "Reaction already exists.")
Ejemplo n.º 6
0
 def test_add_zulip_emoji_reaction(self) -> None:
     result = self.post_reaction(zulip_reaction_info())
     self.assert_json_success(result)