Пример #1
0
 def test_basic_json(self):
     expected = {
         "confirm": {
             "emoji": True,
             "text": "Yes",
             "type": "plain_text"
         },
         "deny": {
             "emoji": True,
             "text": "No",
             "type": "plain_text"
         },
         "text": {
             "text": "are you sure?",
             "type": "mrkdwn"
         },
         "title": {
             "emoji": True,
             "text": "some title",
             "type": "plain_text"
         },
     }
     simple_object = ConfirmObject(title="some title", text="are you sure?")
     self.assertDictEqual(expected, simple_object.to_dict())
     self.assertDictEqual(expected, simple_object.to_dict("block"))
     self.assertDictEqual(
         {
             "text": "are you sure?",
             "title": "some title",
             "ok_text": "Okay",
             "dismiss_text": "Cancel",
         },
         simple_object.to_dict("action"),
     )
Пример #2
0
    def test_json(self):
        self.assertDictEqual(
            ActionButton(name="button_1", text="Click me!",
                         value="btn_1").to_dict(),
            {
                "name": "button_1",
                "text": "Click me!",
                "value": "btn_1",
                "type": "button",
            },
        )

        confirm = ConfirmObject(title="confirm_title", text="confirm_text")
        self.assertDictEqual(
            ActionButton(
                name="button_1",
                text="Click me!",
                value="btn_1",
                confirm=confirm,
                style="danger",
            ).to_dict(),
            {
                "name": "button_1",
                "text": "Click me!",
                "value": "btn_1",
                "type": "button",
                "confirm": confirm.to_dict("action"),
                "style": "danger",
            },
        )
    def test_json(self):
        self.assertDictEqual(
            {
                "text": {"emoji": True, "text": "button text", "type": "plain_text"},
                "action_id": "some_button",
                "value": "button_123",
                "type": "button",
            },
            ButtonElement(
                text="button text", action_id="some_button", value="button_123"
            ).to_dict(),
        )

        confirm = ConfirmObject(title="really?", text="are you sure?")
        self.assertDictEqual(
            {
                "text": {"emoji": True, "text": "button text", "type": "plain_text"},
                "action_id": "some_button",
                "value": "button_123",
                "type": "button",
                "style": "primary",
                "confirm": confirm.to_dict(),
            },
            ButtonElement(
                text="button text",
                action_id="some_button",
                value="button_123",
                style="primary",
                confirm=confirm,
            ).to_dict(),
        )
Пример #4
0
    def test_passing_text_objects(self):
        direct_construction = ConfirmObject(title="title",
                                            text="Are you sure?")

        mrkdwn = MarkdownTextObject(text="Are you sure?")

        preconstructed = ConfirmObject(title="title", text=mrkdwn)

        self.assertDictEqual(direct_construction.to_dict(),
                             preconstructed.to_dict())

        plaintext = PlainTextObject(text="Are you sure?", emoji=False)

        passed_plaintext = ConfirmObject(title="title", text=plaintext)

        self.assertDictEqual(
            {
                "confirm": {
                    "emoji": True,
                    "text": "Yes",
                    "type": "plain_text"
                },
                "deny": {
                    "emoji": True,
                    "text": "No",
                    "type": "plain_text"
                },
                "text": {
                    "emoji": False,
                    "text": "Are you sure?",
                    "type": "plain_text"
                },
                "title": {
                    "emoji": True,
                    "text": "title",
                    "type": "plain_text"
                },
            },
            passed_plaintext.to_dict(),
        )
Пример #5
0
 def test_confirm_overrides(self):
     confirm = ConfirmObject(
         title="some title",
         text="are you sure?",
         confirm="I'm really sure",
         deny="Nevermind",
     )
     expected = {
         "confirm": {
             "text": "I'm really sure",
             "type": "plain_text",
             "emoji": True
         },
         "deny": {
             "text": "Nevermind",
             "type": "plain_text",
             "emoji": True
         },
         "text": {
             "text": "are you sure?",
             "type": "mrkdwn"
         },
         "title": {
             "text": "some title",
             "type": "plain_text",
             "emoji": True
         },
     }
     self.assertDictEqual(expected, confirm.to_dict())
     self.assertDictEqual(expected, confirm.to_dict("block"))
     self.assertDictEqual(
         {
             "text": "are you sure?",
             "title": "some title",
             "ok_text": "I'm really sure",
             "dismiss_text": "Nevermind",
         },
         confirm.to_dict("action"),
     )