示例#1
0
    def test_basic_json(self):
        self.elements = [
            ImageElement(
                image_url=
                "https://api.slack.com/img/blocks/bkb_template_images/palmtree.png",
                alt_text="palmtree",
            ),
            PlainTextObject(text="Just text"),
        ]
        e = {
            "elements": [
                {
                    "type": "image",
                    "image_url":
                    "https://api.slack.com/img/blocks/bkb_template_images/palmtree.png",
                    "alt_text": "palmtree",
                },
                {
                    "type": "plain_text",
                    "text": "Just text"
                },
            ],
            "type":
            "context",
        }
        d = ContextBlock(elements=self.elements).to_dict()
        self.assertDictEqual(e, d)

        with self.assertRaises(SlackObjectFormationError):
            ContextBlock(elements=self.elements * 6).to_dict()
示例#2
0
 def test_document(self):
     input = {
         "type": "context",
         "elements": [
             {
                 "type": "image",
                 "image_url": "https://image.freepik.com/free-photo/red-drawing-pin_1156-445.jpg",
                 "alt_text": "images",
             },
             {"type": "mrkdwn", "text": "Location: **Dogpatch**"},
         ],
     }
     self.assertDictEqual(input, ContextBlock(**input).to_dict())
 def test_home_tab_construction(self):
     home_tab_view = View(
         type="home",
         blocks=[
             SectionBlock(
                 text=MarkdownTextObject(
                     text="*Here's what you can do with Project Tracker:*"
                 ),
             ),
             ActionsBlock(
                 elements=[
                     ButtonElement(
                         text=PlainTextObject(text="Create New Task", emoji=True),
                         style="primary",
                         value="create_task",
                     ),
                     ButtonElement(
                         text=PlainTextObject(text="Create New Project", emoji=True),
                         value="create_project",
                     ),
                     ButtonElement(
                         text=PlainTextObject(text="Help", emoji=True),
                         value="help",
                     ),
                 ],
             ),
             ContextBlock(
                 elements=[
                     ImageElement(
                         image_url="https://api.slack.com/img/blocks/bkb_template_images/placeholder.png",
                         alt_text="placeholder",
                     ),
                 ],
             ),
             SectionBlock(
                 text=MarkdownTextObject(text="*Your Configurations*"),
             ),
             DividerBlock(),
             SectionBlock(
                 text=MarkdownTextObject(
                     text="*#public-relations*\n<fakelink.toUrl.com|PR Strategy 2019> posts new tasks, comments, and project updates to <fakelink.toChannel.com|#public-relations>"
                 ),
                 accessory=ButtonElement(
                     text=PlainTextObject(text="Edit", emoji=True),
                     value="public-relations",
                 ),
             ),
         ],
     )
     home_tab_view.validate_json()