Example #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())
Example #2
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()
Example #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()
Example #5
0
 def test_alt_text_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ImageElement(image_url="http://google.com",
                      alt_text=STRING_3001_CHARS).to_dict()
Example #6
0
 def test_image_url_length(self):
     with self.assertRaises(SlackObjectFormationError):
         ImageElement(image_url=STRING_3001_CHARS,
                      alt_text="text").to_dict()
Example #7
0
 def setUp(self) -> None:
     self.elements = [
         ImageElement(image_url="http://google.com", alt_text="google"),
         PlainTextObject(text="Just text"),
     ]