Beispiel #1
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(),
        )
    def test_json(self):
        self.assertDictEqual(
            ExternalDataSelectElement(placeholder="selectedValue",
                                      action_id="dropdown",
                                      min_query_length=5).to_dict(),
            {
                "placeholder": {
                    "emoji": True,
                    "text": "selectedValue",
                    "type": "plain_text",
                },
                "action_id": "dropdown",
                "min_query_length": 5,
                "type": "external_select",
            },
        )

        self.assertDictEqual(
            ExternalDataSelectElement(
                placeholder="selectedValue",
                action_id="dropdown",
                confirm=ConfirmObject(title="title", text="text"),
            ).to_dict(),
            {
                "placeholder": {
                    "emoji": True,
                    "text": "selectedValue",
                    "type": "plain_text",
                },
                "action_id":
                "dropdown",
                "confirm":
                ConfirmObject(title="title", text="text").to_dict("block"),
                "type":
                "external_select",
            },
        )
Beispiel #3
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"),
     )
Beispiel #4
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)
Beispiel #6
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)
Beispiel #7
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",
         },
     )
Beispiel #8
0
    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(),
        )
 def test_deny_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(
             title=PlainTextObject(text="title"),
             text=MarkdownTextObject(text="Are you sure?"),
             deny=PlainTextObject(text=STRING_51_CHARS)).to_dict()
 def test_text_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(
             title=PlainTextObject(text="title"),
             text=PlainTextObject(text=STRING_301_CHARS)).to_dict()
Beispiel #11
0
 def test_deny_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title="title",
                       text="Are you sure?",
                       deny=STRING_51_CHARS).to_dict()
Beispiel #12
0
 def test_title_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title=STRING_301_CHARS,
                       text="Are you sure?").to_dict()