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)
class SelectElementTests(unittest.TestCase): option_one = Option.from_single_value("one") option_two = Option.from_single_value("two") options = [option_one, option_two, Option.from_single_value("three")] def test_json(self): self.maxDiff = None self.assertDictEqual( SelectElement( placeholder="selectedValue", action_id="dropdown", options=self.options, initial_option=self.option_two, ).to_dict(), { "placeholder": { "emoji": True, "text": "selectedValue", "type": "plain_text", }, "action_id": "dropdown", "options": [o.to_dict("block") for o in self.options], "initial_option": self.option_two.to_dict(), "type": "static_select", }, ) self.assertDictEqual( SelectElement( placeholder="selectedValue", action_id="dropdown", options=self.options, confirm=ConfirmObject(title="title", text="text"), ).to_dict(), { "placeholder": { "emoji": True, "text": "selectedValue", "type": "plain_text", }, "action_id": "dropdown", "options": [o.to_dict("block") for o in self.options], "confirm": ConfirmObject(title="title", text="text").to_dict("block"), "type": "static_select", }, ) def test_options_length(self): with self.assertRaises(SlackObjectFormationError): SelectElement( placeholder="select", action_id="selector", options=[self.option_one] * 101, ).to_dict()
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_from_single_value(self): option = Option(text=PlainTextObject(text="option_1"), value="option_1") self.assertDictEqual( option.to_dict("text"), option.from_single_value("option_1").to_dict("text"), )
def test_json(self): option = Option.from_single_value("one") self.assertDictEqual( ActionExternalSelector(name="select_1", text="selector_1", min_query_length=3).to_dict(), { "name": "select_1", "text": "selector_1", "min_query_length": 3, "type": "select", "data_source": "external", }, ) self.assertDictEqual( ActionExternalSelector(name="select_1", text="selector_1", selected_option=option).to_dict(), { "name": "select_1", "text": "selector_1", "selected_options": [option.to_dict("action")], "type": "select", "data_source": "external", }, )
def test_basic_json_formation(self): options = [ Option.from_single_value("one"), Option.from_single_value("two"), Option.from_single_value("three"), ] self.assertDictEqual( DialogStaticSelector(name="dialog", label="Dialog", options=options).to_dict(), { "optional": False, "label": "Dialog", "type": "select", "name": "dialog", "options": [ { "label": "one", "value": "one" }, { "label": "two", "value": "two" }, { "label": "three", "value": "three" }, ], "data_source": "static", }, )
def test_basic_json_formation(self): o = Option.from_single_value("one") self.assertDictEqual( DialogExternalSelector( name="dialog", label="Dialog", value=o, min_query_length=3, optional=True, placeholder="something", ).to_dict(), { "optional": True, "label": "Dialog", "type": "select", "name": "dialog", "min_query_length": 3, "placeholder": "something", "selected_options": [o.to_dict("dialog")], "data_source": "external", }, )
class StaticSelectElementTests(unittest.TestCase): maxDiff = None 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()) def test_document_option_groups(self): input = { "action_id": "text1234", "type": "static_select", "placeholder": { "type": "plain_text", "text": "Select an item" }, "option_groups": [ { "label": { "type": "plain_text", "text": "Group 1" }, "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", }, ], }, { "label": { "type": "plain_text", "text": "Group 2" }, "options": [{ "text": { "type": "plain_text", "text": "*this is plain_text text*", }, "value": "value-3", }], }, ], } self.assertDictEqual(input, StaticSelectElement(**input).to_dict()) option_one = Option.from_single_value("one") option_two = Option.from_single_value("two") options = [option_one, option_two, Option.from_single_value("three")] 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_options_length(self): with self.assertRaises(SlackObjectFormationError): StaticSelectElement( placeholder="select", action_id="selector", options=[self.option_one] * 101, ).to_dict()
def setUp(self) -> None: self.selected_opt = Option.from_single_value("U12345")
def test_from_single_value(self): option = Option(label="option_1", value="option_1") self.assertDictEqual( option.to_dict("text"), option.from_single_value("option_1").to_dict("text"), )