Ejemplo n.º 1
0
    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)
Ejemplo n.º 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"),
            ],
        ),
    ])
Ejemplo n.º 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)
        ]
Ejemplo n.º 4
0
 def test_options_length(self):
     with self.assertRaises(SlackObjectFormationError):
         OptionGroup(label="option_group",
                     options=self.common_options * 34).to_dict("text")
Ejemplo n.º 5
0
 def test_label_length(self):
     with self.assertRaises(SlackObjectFormationError):
         OptionGroup(label=STRING_301_CHARS,
                     options=self.common_options).to_dict("text")
Ejemplo n.º 6
0
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()