def test_image_set_size(self):
     image = Image(URL)
     image.set_size(ImageSize.LARGE)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "size": "large"
     })
 def test_image_set_style(self):
     image = Image(URL)
     image.set_style(ImageStyle.DEFAULT)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "style": "default"
     })
 def test_image_set_spacing(self):
     image = Image(URL)
     image.set_spacing(SpacingStyle.EXTRA_LARGE)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "spacing": "extraLarge"
     })
 def test_image_set_background_color(self):
     image = Image(URL)
     image.set_background_color("abcdef")
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "backgroundColor": "abcdef"
     })
 def test_image_set_id(self):
     image = Image(URL)
     image.set_id("id_image_3")
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "id": "id_image_3"
     })
 def test_image_set_horizontal_alignment(self):
     image = Image(URL)
     image.set_horizontal_alignment(HorizontalAlignment.RIGHT)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "horizontalAlignment": "right"
     })
 def test_image_set_alternate_text(self):
     image = Image(URL)
     image.set_alternate_text("Duis aute irure")
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "altText": "Duis aute irure"
     })
 def test_image_set_requires(self):
     image = Image(URL)
     image.set_requires(self.requires)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "requires": self.requires
     })
 def test_image_set_width(self):
     image = Image(URL)
     image.set_width("128px")
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "width": "128px"
     })
 def test_image_set_select_action(self):
     image = Image(URL)
     image.set_select_action(OpenUrl("www.click.me"))
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "selectAction": {
             "type": "Action.OpenUrl",
             "url": "www.click.me"
         }
     })
 def test_image_set_height(self):
     image = Image(URL)
     image.set_height("42px")
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "height": "42px"
     })
     image.set_height(BlockElementHeight.STRETCH)
     with self.assertRaisesMessage(CardException, "Invalid height type"):
         image.set_height(1234)
 def test_media_set_fallback(self):
     media = Media(sources=[MediaSource("text/html", "www.url.com"), ])
     media.set_fallback(FallbackOption.DROP)
     self.assertDictEqual(media.as_data(), {
         "type": "Media",
         "sources": [{
             "mimeType": "text/html",
             "url": "www.url.com"
         }],
         "fallback": "drop"
     })
     media.set_fallback(Image(URL))
     self.assertDictEqual(media.as_data(), {
         "type": "Media",
         "sources": [{
             "mimeType": "text/html",
             "url": "www.url.com"
         }],
         "fallback": {
             "type": "Image",
             "url": URL
         }
     })
     with self.assertRaisesMessage(CardException, "Invalid fallback type"):
         media.set_fallback(1234)
Beispiel #13
0
 def test_execute_set_set_fallback2(self):
     action = Execute()
     action.set_fallback(Image(URL))
     self.assertDictEqual(action.as_data(), {
         "type": "Action.Execute",
         "fallback": {
             "type": "Image",
             "url": URL
         }
     })
 def test_text_block_set_fallback(self):
     text_block = TextBlock(text="asdf")
     text_block.set_fallback(FallbackOption.DROP)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "fallback": "drop"
     })
     text_block.set_fallback(Image(URL))
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "fallback": {
             "type": "Image",
             "url": URL
         }
     })
     with self.assertRaisesMessage(CardException, "Invalid fallback type"):
         text_block.set_fallback(1234)
 def test_rich_text_block_set_fallback(self):
     rich_text_block = RichTextBlock(inlines=["lorem ipsum", ])
     rich_text_block.set_fallback(FallbackOption.DROP)
     self.assertDictEqual(rich_text_block.as_data(), {
         "type": "RichTextBlock",
         "inlines": ["lorem ipsum", ],
         "fallback": "drop"
     })
     rich_text_block.set_fallback(Image(URL))
     self.assertDictEqual(rich_text_block.as_data(), {
         "type": "RichTextBlock",
         "inlines": ["lorem ipsum", ],
         "fallback": {
             "type": "Image",
             "url": URL
         }
     })
     with self.assertRaisesMessage(CardException, "Invalid fallback type"):
         rich_text_block.set_fallback(1234)
Beispiel #16
0
from django_actionable_messages.adaptive_card.cards import AdaptiveCard
from django_actionable_messages.adaptive_card.containers import Column, ColumnSet
from django_actionable_messages.adaptive_card.elements import TextBlock, Image
from django_actionable_messages.adaptive_card.utils import (
    SCHEMA, FontSize, FontWeight, SpacingStyle, Width, ImageSize,
    HorizontalAlignment, Color)
"""
https://adaptivecards.io/samples/FlightItinerary.html
"""

column_plane = Column(
    width=Width.AUTO,
    items=[
        TextBlock(" "),
        Image(url="http://adaptivecards.io/content/airplane.png",
              size=ImageSize.SMALL,
              spacing=SpacingStyle.NONE)
    ])
column_san_francisco = Column(
    width=1,
    items=[
        TextBlock("San Francisco",
                  horizontal_alignment=HorizontalAlignment.RIGHT,
                  is_subtle=True),
        TextBlock("SFO",
                  horizontal_alignment=HorizontalAlignment.RIGHT,
                  size=FontSize.EXTRA_LARGE,
                  color=Color.ACCENT,
                  spacing=SpacingStyle.NONE)
    ])
column_amsterdam = Column(width=1,
 def test_image_set_is_visible(self):
     image = Image(URL)
     image.set_is_visible(False)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "isVisible": False
     })
     image.set_is_visible(True)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "isVisible": True
     })
     image.set_is_visible()
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "isVisible": True
     })
        choices=[
            InputChoice("I'm allergic to peanuts", "peanut")
        ]
    ),
    TextInput(item_id="ChickenOther", is_multiline=True, placeholder="Any other preparation requests?")
])
adaptive_card2.add_actions(Submit(title="OK", data={"FoodChoice": "Chicken"}))
adaptive_card3 = AdaptiveCard()
adaptive_card3.add_elements([
    TextBlock("Would you like it prepared vegan?", size=FontSize.MEDIUM, wrap=True),
    ToggleInput(item_id="Vegetarian", title="Please prepare it vegan", value_on="vegan", value_off="notVegan"),
    TextInput(item_id="VegOther", is_multiline=True, placeholder="Any other preparation requests?")
])
adaptive_card3.add_actions(Submit(title="OK", data={"FoodChoice": "Chicken"}))

food_order = AdaptiveCard(version="1.0", schema=SCHEMA)
food_order.add_elements([
    TextBlock("Your registration is almost complete", size=FontSize.MEDIUM, weight=FontWeight.BOLDER),
    TextBlock("What type of food do you prefer?", wrap=True),
    ImageSet(images=[
        Image("http://contososcubademo.azurewebsites.net/assets/steak.jpg"),
        Image("http://contososcubademo.azurewebsites.net/assets/chicken.jpg"),
        Image("http://contososcubademo.azurewebsites.net/assets/tofu.jpg")
    ])
])
food_order.add_actions([
    ShowCard(title="Steak", card=adaptive_card1),
    ShowCard(title="Chicken", card=adaptive_card2),
    ShowCard(title="Tofu", card=adaptive_card3)
])
 def test_image_set_separator(self):
     image = Image(URL)
     image.set_separator(False)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "separator": False
     })
     image.set_separator(True)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "separator": True
     })
     image.set_separator()
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "separator": True
     })
 def test_image_set_fallback(self):
     image = Image(URL)
     image.set_fallback(FallbackOption.DROP)
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "fallback": "drop"
     })
     image.set_fallback(Image(URL))
     self.assertDictEqual(image.as_data(), {
         "type": "Image",
         "url": URL,
         "fallback": {
             "type": "Image",
             "url": URL
         }
     })
     with self.assertRaisesMessage(CardException, "Invalid fallback type"):
         image.set_fallback(1234)
https://adaptivecards.io/samples/ActivityUpdate.html
"""

activity_update = AdaptiveCard(version="1.0", schema=SCHEMA)
activity_update.add_elements(
    TextBlock("Publish Adaptive Card schema",
              size=FontSize.MEDIUM,
              weight=FontWeight.BOLDER))
activity_update.add_elements(
    ColumnSet([
        Column(
            width=Width.AUTO,
            items=[
                Image(
                    url=
                    "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
                    size=ImageSize.SMALL,
                    style=ImageStyle.PERSON)
            ]),
        Column(width=Width.STRETCH,
               items=[
                   TextBlock("Matt Hidinger",
                             weight=FontWeight.BOLDER,
                             wrap=True),
                   TextBlock("Created {{DATE(2017-02-14T06:08:39Z, SHORT)}",
                             spacing=SpacingStyle.NONE,
                             is_subtle=True,
                             wrap=True)
               ])
    ]))
activity_update.add_elements(
Beispiel #22
0
from django_actionable_messages.adaptive_card.cards import AdaptiveCard
from django_actionable_messages.adaptive_card.containers import ColumnSet, Column, ImageSet
from django_actionable_messages.adaptive_card.elements import TextBlock, Image
from django_actionable_messages.adaptive_card.types import BackgroundImage
from django_actionable_messages.adaptive_card.utils import (
    SCHEMA, SpacingStyle, ImageSize, Width, FillMode, HorizontalAlignment)
"""
https://adaptivecards.io/samples/Agenda.html
"""

column_set1 = ColumnSet(columns=[
    Column(items=[
        ColumnSet(columns=[
            Column(items=[
                Image(
                    "http://messagecardplayground.azurewebsites.net/assets/LocationGreen_A.png"
                )
            ],
                   width=Width.AUTO),
            Column(items=[
                TextBlock("**Redmond**"),
                TextBlock("8a - 12:30p", spacing=SpacingStyle.NONE)
            ],
                   width=Width.AUTO)
        ])
    ],
           width=1),
    Column(items=[
        ColumnSet(columns=[
            Column(items=[
                Image(