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 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_json_with_confirm(self): confirm = ConfirmObject(title=PlainTextObject(text="title"), text=PlainTextObject(text="text")) select = StaticSelectElement( placeholder=PlainTextObject(text="selectedValue"), action_id="dropdown", options=self.options, confirm=confirm, ).to_dict() coded = { "placeholder": { "emoji": True, "text": "selectedValue", "type": "plain_text", }, "action_id": "dropdown", "options": [o.to_dict() for o in self.options], "confirm": confirm.to_dict(), "type": "static_select", } self.assertDictEqual(select, coded)
def test_json(self): self.maxDiff = None select = StaticSelectElement( placeholder=PlainTextObject(text="selectedValue"), action_id="dropdown", options=self.options, initial_option=self.option_two, ).to_dict() coded = { "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(select, coded)