def test_valid_description_for_blocks(self):
     option = Option(label="label",
                     value="v",
                     description="this is an option")
     self.assertDictEqual(
         option.to_dict(),
         {
             "text": {
                 "type": "plain_text",
                 "text": "label",
                 "emoji": True,
             },
             "value": "v",
             "description": {
                 "type": "plain_text",
                 "text": "this is an option",
                 "emoji": True,
             },
         },
     )
     option = Option(
         # Note that mrkdwn type is not allowed for this (as of April 2021)
         text=PlainTextObject(text="label"),
         value="v",
         description="this is an option",
     )
     self.assertDictEqual(
         option.to_dict(),
         {
             "text": {
                 "type": "plain_text",
                 "text": "label"
             },
             "value": "v",
             "description": {
                 "type": "plain_text",
                 "text": "this is an option",
                 "emoji": True,
             },
         },
     )
 def test_valid_description_for_attachments(self):
     option = Option(label="label",
                     value="v",
                     description="this is an option")
     # legacy message actions in attachments
     self.assertDictEqual(
         option.to_dict("action"),
         {
             "text": "label",
             "value": "v",
             "description": "this is an option",
         },
     )
     self.assertDictEqual(
         option.to_dict("attachment"),
         {
             "text": "label",
             "value": "v",
             "description": "this is an option",
         },
     )
class OptionTests(unittest.TestCase):
    def setUp(self) -> None:
        self.common = Option(label="an option", value="option_1")

    def test_block_style_json(self):
        expected = {
            "text": {
                "type": "plain_text",
                "text": "an option",
                "emoji": True
            },
            "value": "option_1",
        }
        self.assertDictEqual(expected, self.common.to_dict("block"))
        self.assertDictEqual(expected, self.common.to_dict())

    def test_dialog_style_json(self):
        expected = {"label": "an option", "value": "option_1"}
        self.assertDictEqual(expected, self.common.to_dict("dialog"))

    def test_action_style_json(self):
        expected = {"text": "an option", "value": "option_1"}
        self.assertDictEqual(expected, self.common.to_dict("action"))

    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"),
        )

    def test_label_length(self):
        with self.assertRaises(SlackObjectFormationError):
            Option(label=STRING_301_CHARS, value="option_1").to_dict("text")

    def test_value_length(self):
        with self.assertRaises(SlackObjectFormationError):
            Option(label="option_1", value=STRING_301_CHARS).to_dict("text")
 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"),
     )
class OptionTests(unittest.TestCase):
    def setUp(self) -> None:
        self.common = Option(label="an option", value="option_1")

    def test_block_style_json(self):
        expected = {
            "text": {
                "type": "plain_text",
                "text": "an option",
                "emoji": True
            },
            "value": "option_1",
        }
        self.assertDictEqual(expected, self.common.to_dict("block"))
        self.assertDictEqual(expected, self.common.to_dict())

    def test_dialog_style_json(self):
        expected = {"label": "an option", "value": "option_1"}
        self.assertDictEqual(expected, self.common.to_dict("dialog"))

    def test_action_style_json(self):
        expected = {"text": "an option", "value": "option_1"}
        self.assertDictEqual(expected, self.common.to_dict("action"))

    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"),
        )

    def test_label_length(self):
        with self.assertRaises(SlackObjectFormationError):
            Option(label=STRING_301_CHARS, value="option_1").to_dict("text")

    def test_value_length(self):
        with self.assertRaises(SlackObjectFormationError):
            Option(label="option_1", value=STRING_301_CHARS).to_dict("text")

    def test_valid_description_for_blocks(self):
        option = Option(label="label",
                        value="v",
                        description="this is an option")
        self.assertDictEqual(
            option.to_dict(),
            {
                "text": {
                    "type": "plain_text",
                    "text": "label",
                    "emoji": True,
                },
                "value": "v",
                "description": {
                    "type": "plain_text",
                    "text": "this is an option",
                    "emoji": True,
                },
            },
        )
        option = Option(
            # Note that mrkdwn type is not allowed for this (as of April 2021)
            text=PlainTextObject(text="label"),
            value="v",
            description="this is an option",
        )
        self.assertDictEqual(
            option.to_dict(),
            {
                "text": {
                    "type": "plain_text",
                    "text": "label"
                },
                "value": "v",
                "description": {
                    "type": "plain_text",
                    "text": "this is an option",
                    "emoji": True,
                },
            },
        )

    def test_valid_description_for_attachments(self):
        option = Option(label="label",
                        value="v",
                        description="this is an option")
        # legacy message actions in attachments
        self.assertDictEqual(
            option.to_dict("action"),
            {
                "text": "label",
                "value": "v",
                "description": "this is an option",
            },
        )
        self.assertDictEqual(
            option.to_dict("attachment"),
            {
                "text": "label",
                "value": "v",
                "description": "this is an option",
            },
        )