def setUp(self) -> None:
        self.common_options = [
            Option.from_single_value("one"),
            Option.from_single_value("two"),
            Option.from_single_value("three"),
        ]

        self.common = OptionGroup(label="an option",
                                  options=self.common_options)
Beispiel #2
0
def show_multi_options(ack: Ack) -> None:
    ack(option_groups=[
        OptionGroup(
            label=PlainTextObject(text="Group 1"),
            options=[
                Option(text=PlainTextObject(text="Option 1"), value="1-1"),
                Option(text=PlainTextObject(text="Option 2"), value="1-2"),
            ],
        ),
        OptionGroup(
            label=PlainTextObject(text="Group 2"),
            options=[
                Option(text=PlainTextObject(text="Option 1"), value="2-1"),
            ],
        ),
    ])
Beispiel #3
0
    def setUp(self) -> None:
        self.options = [
            Option.from_single_value("one"),
            Option.from_single_value("two"),
            Option.from_single_value("three"),
        ]

        self.option_group = [
            OptionGroup(label="group_1", options=self.options)
        ]
 def test_options_length(self):
     with self.assertRaises(SlackObjectFormationError):
         OptionGroup(label="option_group",
                     options=self.common_options * 34).to_dict("text")
 def test_label_length(self):
     with self.assertRaises(SlackObjectFormationError):
         OptionGroup(label=STRING_301_CHARS,
                     options=self.common_options).to_dict("text")
class OptionGroupTests(unittest.TestCase):
    maxDiff = None

    def setUp(self) -> None:
        self.common_options = [
            Option.from_single_value("one"),
            Option.from_single_value("two"),
            Option.from_single_value("three"),
        ]

        self.common = OptionGroup(label="an option",
                                  options=self.common_options)

    def test_block_style_json(self):
        expected = {
            "label": {
                "emoji": True,
                "text": "an option",
                "type": "plain_text"
            },
            "options": [
                {
                    "text": {
                        "emoji": True,
                        "text": "one",
                        "type": "plain_text"
                    },
                    "value": "one",
                },
                {
                    "text": {
                        "emoji": True,
                        "text": "two",
                        "type": "plain_text"
                    },
                    "value": "two",
                },
                {
                    "text": {
                        "emoji": True,
                        "text": "three",
                        "type": "plain_text"
                    },
                    "value": "three",
                },
            ],
        }
        self.assertDictEqual(expected, self.common.to_dict("block"))
        self.assertDictEqual(expected, self.common.to_dict())

    def test_dialog_style_json(self):
        self.assertDictEqual(
            {
                "label":
                "an option",
                "options": [
                    {
                        "label": "one",
                        "value": "one"
                    },
                    {
                        "label": "two",
                        "value": "two"
                    },
                    {
                        "label": "three",
                        "value": "three"
                    },
                ],
            },
            self.common.to_dict("dialog"),
        )

    def test_action_style_json(self):
        self.assertDictEqual(
            {
                "text":
                "an option",
                "options": [
                    {
                        "text": "one",
                        "value": "one"
                    },
                    {
                        "text": "two",
                        "value": "two"
                    },
                    {
                        "text": "three",
                        "value": "three"
                    },
                ],
            },
            self.common.to_dict("action"),
        )

    def test_label_length(self):
        with self.assertRaises(SlackObjectFormationError):
            OptionGroup(label=STRING_301_CHARS,
                        options=self.common_options).to_dict("text")

    def test_options_length(self):
        with self.assertRaises(SlackObjectFormationError):
            OptionGroup(label="option_group",
                        options=self.common_options * 34).to_dict("text")

    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_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()