Beispiel #1
0
 def test_document(self):
     input = {
         "type": "image",
         "image_url": "http://placekitten.com/700/500",
         "alt_text": "Multiple cute kittens",
     }
     self.assertDictEqual(input, ImageElement(**input).to_dict())
    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()
Beispiel #3
0
 def test_json(self):
     self.assertDictEqual(
         {
             "image_url": "http://google.com",
             "alt_text": "not really an image",
             "type": "image",
         },
         ImageElement(image_url="http://google.com",
                      alt_text="not really an image").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()
Beispiel #5
0
 def test_element_parsing(self):
     elements = [
         ButtonElement(text="Click me", action_id="reg_button", value="1"),
         StaticSelectElement(options=[Option(value="SelectOption")]),
         ImageElement(image_url="url", alt_text="alt-text"),
         OverflowMenuElement(
             options=[Option(value="MenuOption1"), Option(value="MenuOption2")]
         ),
     ]
     input = {
         "type": "actions",
         "block_id": "actionblock789",
         "elements": [e.to_dict() for e in elements],
     }
     parsed_elements = ActionsBlock(**input).elements
     self.assertEqual(len(elements), len(parsed_elements))
     for original, parsed in zip(elements, parsed_elements):
         self.assertEqual(type(original), type(parsed))
         self.assertDictEqual(original.to_dict(), parsed.to_dict())
Beispiel #6
0
 def test_alt_text_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ImageElement(image_url="http://google.com",
                      alt_text=STRING_3001_CHARS).to_dict()
Beispiel #7
0
 def test_image_url_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ImageElement(image_url=STRING_3001_CHARS,
                      alt_text="text").to_dict()