Ejemplo n.º 1
0
    def test_with_static_select_element(self):
        self.maxDiff = None

        elem = StaticSelectElement(
            action_id="action-id",
            initial_option=Option(value="option-1", text="Option 1"),
            options=[
                Option(value="option-1", text="Option 1"),
                Option(value="option-2", text="Option 2"),
                Option(value="option-3", text="Option 3"),
            ],
        )
        expected = {
            "action_id":
            "action-id",
            "initial_option": {
                "text": {
                    "emoji": True,
                    "text": "Option 1",
                    "type": "plain_text"
                },
                "value": "option-1",
            },
            "options": [
                {
                    "text": {
                        "emoji": True,
                        "text": "Option 1",
                        "type": "plain_text"
                    },
                    "value": "option-1",
                },
                {
                    "text": {
                        "emoji": True,
                        "text": "Option 2",
                        "type": "plain_text"
                    },
                    "value": "option-2",
                },
                {
                    "text": {
                        "emoji": True,
                        "text": "Option 3",
                        "type": "plain_text"
                    },
                    "value": "option-3",
                },
            ],
            "type":
            "static_select",
        }
        self.assertDictEqual(expected, elem.to_dict())
Ejemplo n.º 2
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(),
        )
Ejemplo n.º 3
0
 def test_options_length(self):
     with self.assertRaises(SlackObjectFormationError):
         StaticSelectElement(
             placeholder="select",
             action_id="selector",
             options=[self.option_one] * 101,
         ).to_dict()
Ejemplo n.º 4
0
 def test_document_options(self):
     input = {
         "action_id":
         "text1234",
         "type":
         "static_select",
         "placeholder": {
             "type": "plain_text",
             "text": "Select an item"
         },
         "options": [
             {
                 "text": {
                     "type": "plain_text",
                     "text": "*this is plain_text text*"
                 },
                 "value": "value-0",
             },
             {
                 "text": {
                     "type": "plain_text",
                     "text": "*this is plain_text text*"
                 },
                 "value": "value-1",
             },
             {
                 "text": {
                     "type": "plain_text",
                     "text": "*this is plain_text text*"
                 },
                 "value": "value-2",
             },
         ],
     }
     self.assertDictEqual(input, StaticSelectElement(**input).to_dict())
Ejemplo n.º 5
0
 def test_element_parsing(self):
     elements = [
         ButtonElement(text="Click me", action_id="reg_button", value="1"),
         StaticSelectElement(options=[Option(value="SelectOption")]),
         ImageElement(image_url="url", alt_text="alt-text"),
         OverflowMenuElement(
             options=[Option(value="MenuOption1"), Option(value="MenuOption2")]
         ),
     ]
     input = {
         "type": "actions",
         "block_id": "actionblock789",
         "elements": [e.to_dict() for e in elements],
     }
     parsed_elements = ActionsBlock(**input).elements
     self.assertEqual(len(elements), len(parsed_elements))
     for original, parsed in zip(elements, parsed_elements):
         self.assertEqual(type(original), type(parsed))
         self.assertDictEqual(original.to_dict(), parsed.to_dict())