示例#1
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",
            },
        )
示例#2
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)
    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_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",
            },
        )
示例#6
0
    def test_text_length_with_object(self):
        with self.assertRaises(SlackObjectFormationError):
            plaintext = PlainTextObject(text=STRING_301_CHARS)
            ConfirmObject(title="title", text=plaintext).to_dict()

        with self.assertRaises(SlackObjectFormationError):
            markdown = MarkdownTextObject(text=STRING_301_CHARS)
            ConfirmObject(title="title", text=markdown).to_dict()
示例#7
0
    def test_json(self):
        dict_options = []
        for o in self.options:
            dict_options.append(o.to_dict())

        self.assertDictEqual(
            {
                "placeholder": {
                    "emoji": True,
                    "text": "selectedValue",
                    "type": "plain_text",
                },
                "action_id": "dropdown",
                "options": dict_options,
                "initial_option": self.option_two.to_dict(),
                "type": "static_select",
            },
            StaticSelectElement(
                placeholder="selectedValue",
                action_id="dropdown",
                options=self.options,
                initial_option=self.option_two,
            ).to_dict(),
        )

        self.assertDictEqual(
            {
                "placeholder": {
                    "emoji": True,
                    "text": "selectedValue",
                    "type": "plain_text",
                },
                "action_id":
                "dropdown",
                "options":
                dict_options,
                "confirm":
                ConfirmObject(title="title", text="text").to_dict("block"),
                "type":
                "static_select",
            },
            StaticSelectElement(
                placeholder="selectedValue",
                action_id="dropdown",
                options=self.options,
                confirm=ConfirmObject(title="title", text="text"),
            ).to_dict(),
        )
 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=PlainTextObject(text="some title"),
         text=MarkdownTextObject(text="are you sure?")).to_dict()
     self.assertDictEqual(simple_object, expected)
示例#9
0
 def test_confirm_style_validation(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject.parse(
             {
                 "title": {"type": "plain_text", "text": "Are you sure?"},
                 "text": {
                     "type": "mrkdwn",
                     "text": "Wouldn't you prefer a good game of _chess_?",
                 },
                 "confirm": {"type": "plain_text", "text": "Do it"},
                 "deny": {
                     "type": "plain_text",
                     "text": "Stop, I've changed my mind!",
                 },
                 "style": "something-wrong",
             }
         ).validate_json()
示例#10
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)
示例#12
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)
示例#13
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",
         },
     )
    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"
                },
            },
        )
示例#15
0
 def test_confirm_style(self):
     obj = ConfirmObject.parse(
         {
             "title": {"type": "plain_text", "text": "Are you sure?"},
             "text": {
                 "type": "mrkdwn",
                 "text": "Wouldn't you prefer a good game of _chess_?",
             },
             "confirm": {"type": "plain_text", "text": "Do it"},
             "deny": {"type": "plain_text", "text": "Stop, I've changed my mind!"},
             "style": "primary",
         }
     )
     obj.validate_json()
     self.assertEqual("primary", obj.style)
 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()
示例#18
0
 def test_title_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title=STRING_301_CHARS,
                       text="Are you sure?").to_dict()
示例#19
0
 def test_deny_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title="title",
                       text="Are you sure?",
                       deny=STRING_51_CHARS).to_dict()