Esempio n. 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",
             "verbatim": False
         },
         "title": {
             "emoji": True,
             "text": "some title",
             "type": "plain_text"
         },
     }
     simple_object = ConfirmObject(title="some title", text="are you sure?")
     self.assertDictEqual(simple_object.to_dict(), expected)
     self.assertDictEqual(simple_object.to_dict("block"), expected)
     self.assertDictEqual(
         simple_object.to_dict("action"),
         {
             "text": "are you sure?",
             "title": "some title",
             "ok_text": "Okay",
             "dismiss_text": "Cancel",
         },
     )
 def test_confirm_overrides(self):
     confirm = ConfirmObject(
         title=PlainTextObject(text="some title"),
         text=MarkdownTextObject(text="are you sure?"),
         confirm=PlainTextObject(text="I'm really sure"),
         deny=PlainTextObject(text="Nevermind"),
     )
     expected = {
         "confirm": {
             "emoji": True,
             "text": "I'm really sure",
             "type": "plain_text"
         },
         "deny": {
             "emoji": True,
             "text": "Nevermind",
             "type": "plain_text"
         },
         "text": {
             "text": "are you sure?",
             "type": "mrkdwn",
             "verbatim": False
         },
         "title": {
             "emoji": True,
             "text": "some title",
             "type": "plain_text"
         },
     }
     self.assertDictEqual(confirm.to_dict(), expected)
Esempio n. 3
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(
            ButtonElement(
                text="button text", action_id="some_button", value="button_123"
            ).to_dict(),
            {
                "text": {"emoji": True, "text": "button text", "type": "plain_text"},
                "action_id": "some_button",
                "value": "button_123",
                "type": "button",
            },
        )
        confirm = ConfirmObject(title="really?", text="are you sure?")

        self.assertDictEqual(
            ButtonElement(
                text="button text",
                action_id="some_button",
                value="button_123",
                style="primary",
                confirm=confirm,
            ).to_dict(),
            {
                "text": {"emoji": True, "text": "button text", "type": "plain_text"},
                "action_id": "some_button",
                "value": "button_123",
                "type": "button",
                "style": "primary",
                "confirm": confirm.to_dict(),
            },
        )
    def test_passing_text_objects(self):
        direct_construction = ConfirmObject(
            title=PlainTextObject(text="title"),
            text=MarkdownTextObject(text="Are you sure?"))

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

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

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

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

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

        self.assertDictEqual(
            passed_plaintext.to_dict(),
            {
                "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"
                },
            },
        )
Esempio n. 6
0
 def test_confirm_overrides(self):
     confirm = ConfirmObject(
         title="some title",
         text="are you sure?",
         confirm="I'm really sure",
         deny="Nevermind",
     )
     expected = {
         "confirm": {
             "emoji": True,
             "text": "I'm really sure",
             "type": "plain_text"
         },
         "deny": {
             "emoji": True,
             "text": "Nevermind",
             "type": "plain_text"
         },
         "text": {
             "text": "are you sure?",
             "type": "mrkdwn",
             "verbatim": False
         },
         "title": {
             "emoji": True,
             "text": "some title",
             "type": "plain_text"
         },
     }
     self.assertDictEqual(confirm.to_dict(), expected)
     self.assertDictEqual(confirm.to_dict("block"), expected)
     self.assertDictEqual(
         confirm.to_dict("action"),
         {
             "text": "are you sure?",
             "title": "some title",
             "ok_text": "I'm really sure",
             "dismiss_text": "Nevermind",
         },
     )
Esempio n. 7
0
 def test_json_with_confirm(self):
     confirm = ConfirmObject(title=PlainTextObject(text="really?"),
                             text=PlainTextObject(text="are you sure?"))
     button = ButtonElement(
         text=PlainTextObject(text="button text"),
         action_id="some_button",
         value="button_123",
         style="primary",
         confirm=confirm,
     ).to_dict()
     coded = {
         "text": {"emoji": True, "text": "button text", "type": "plain_text"},
         "action_id": "some_button",
         "value": "button_123",
         "type": "button",
         "style": "primary",
         "confirm": confirm.to_dict(),
     }
     self.assertDictEqual(button, coded)
    def test_json_with_confirm(self):
        confirm = ConfirmObject(title=PlainTextObject(text="confirm_title"),
                                text=MarkdownTextObject(text="confirm_text"))
        button = ActionButton(
            name="button_1",
            text="Click me!",
            value="btn_1",
            confirm=confirm,
            style="danger",
        ).to_dict()

        coded = {
            "name": "button_1",
            "text": "Click me!",
            "value": "btn_1",
            "type": "button",
            "confirm": confirm.to_dict("action"),
            "style": "danger",
        }
        self.assertDictEqual(button, coded)
Esempio n. 9
0
 def test_json_with_confirm(self):
     confirm = ConfirmObject(title=PlainTextObject(text="title"), text=PlainTextObject(text="text"))
     select = StaticSelectElement(
         placeholder=PlainTextObject(text="selectedValue"),
         action_id="dropdown",
         options=self.options,
         confirm=confirm,
     ).to_dict()
     coded = {
         "placeholder": {
             "emoji": True,
             "text": "selectedValue",
             "type": "plain_text",
         },
         "action_id": "dropdown",
         "options": [o.to_dict() for o in self.options],
         "confirm": confirm.to_dict(),
         "type": "static_select",
     }
     self.assertDictEqual(select, coded)