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"
         },
         "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"),
     )
Esempio n. 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(),
        )
 def test_json(self):
     self.assertDictEqual(
         {
             "placeholder": {
                 "emoji": True,
                 "text": "selectedValue",
                 "type": "plain_text",
             },
             "action_id": "dropdown",
             "min_query_length": 5,
             "type": "external_select",
         },
         ExternalDataSelectElement(
             placeholder="selectedValue", action_id="dropdown", min_query_length=5
         ).to_dict(),
     )
     self.assertDictEqual(
         {
             "placeholder": {
                 "emoji": True,
                 "text": "selectedValue",
                 "type": "plain_text",
             },
             "action_id": "dropdown",
             "confirm": ConfirmObject(title="title", text="text").to_dict("block"),
             "type": "external_select",
         },
         ExternalDataSelectElement(
             placeholder="selectedValue",
             action_id="dropdown",
             confirm=ConfirmObject(title="title", text="text"),
         ).to_dict(),
     )
Esempio n. 5
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()
Esempio n. 6
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(),
        )
Esempio n. 7
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()
Esempio n. 8
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"),
     )
Esempio n. 9
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(),
        )
Esempio n. 10
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)
Esempio n. 11
0
 def test_deny_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title="title",
                       text="Are you sure?",
                       deny=STRING_51_CHARS).to_dict()
Esempio n. 12
0
 def test_text_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title="title", text=STRING_301_CHARS).to_dict()
Esempio n. 13
0
 def test_title_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ConfirmObject(title=STRING_301_CHARS,
                       text="Are you sure?").to_dict()