Esempio n. 1
0
    def test_json(self):
        self.assertDictEqual(
            {
                "text": {
                    "text": "some text",
                    "type": "mrkdwn"
                },
                "block_id": "a_block",
                "type": "section",
            },
            SectionBlock(text="some text", block_id="a_block").to_dict(),
        )

        self.assertDictEqual(
            {
                "text": {
                    "text": "some text",
                    "type": "mrkdwn"
                },
                "fields": [
                    {
                        "text": "field0",
                        "type": "mrkdwn"
                    },
                    {
                        "text": "field1",
                        "type": "mrkdwn"
                    },
                    {
                        "text": "field2",
                        "type": "mrkdwn"
                    },
                    {
                        "text": "field3",
                        "type": "mrkdwn"
                    },
                    {
                        "text": "field4",
                        "type": "mrkdwn"
                    },
                ],
                "type":
                "section",
            },
            SectionBlock(text="some text",
                         fields=[f"field{i}" for i in range(5)]).to_dict(),
        )

        button = LinkButtonElement(text="Click me!", url="http://google.com")
        self.assertDictEqual(
            {
                "type": "section",
                "text": {
                    "text": "some text",
                    "type": "mrkdwn"
                },
                "accessory": button.to_dict(),
            },
            SectionBlock(text="some text", accessory=button).to_dict(),
        )
 def test_json(self):
     button = LinkButtonElement(text="button text", url="http://google.com")
     self.assertDictEqual(
         button.to_dict(),
         {
             "text": {"emoji": True, "text": "button text", "type": "plain_text"},
             "url": "http://google.com",
             "type": "button",
             "action_id": button.action_id,
         },
     )
Esempio n. 3
0
 def test_json_with_accessory(self):
     button = LinkButtonElement(text=PlainTextObject(text="Click me!"),
                                url="http://google.com")
     section = SectionBlock(text=MarkdownTextObject(text="some text"),
                            accessory=button).to_dict()
     coded = {
         "text": {
             "text": "some text",
             "type": "mrkdwn",
             "verbatim": False
         },
         "accessory": button.to_dict(),
         "type": "section",
     }
     self.assertDictEqual(section, coded)
Esempio n. 4
0
 def setUp(self) -> None:
     self.elements = [
         ButtonElement(text=PlainTextObject(text="Click me"),
                       action_id="reg_button",
                       value="1"),
         LinkButtonElement(text=PlainTextObject(text="URL Button"),
                           url="http://google.com"),
     ]
Esempio n. 5
0
 def test_document_3(self):
     input = {
         "type": "button",
         "text": {
             "type": "plain_text",
             "text": "Link Button"
         },
         "url": "https://api.slack.com/block-kit",
     }
     self.assertDictEqual(input, ButtonElement(**input).to_dict())
     self.assertDictEqual(input, LinkButtonElement(**input).to_dict())
    def test_json(self):
        self.elements = [
            ButtonElement(text="Click me", action_id="reg_button", value="1"),
            LinkButtonElement(text="URL Button", url="http://google.com"),
        ]
        self.dict_elements = []
        for e in self.elements:
            self.dict_elements.append(e.to_dict())

        self.assertDictEqual(
            {"elements": self.dict_elements, "type": "actions"},
            ActionsBlock(elements=self.elements).to_dict(),
        )
        with self.assertRaises(SlackObjectFormationError):
            ActionsBlock(elements=self.elements * 3).to_dict()
Esempio n. 7
0
 def test_url_length(self):
     with self.assertRaises(SlackObjectFormationError):
         LinkButtonElement(text="Button", url=STRING_3001_CHARS).to_dict()