def test_text_block_set_text(self):
     text_block = TextBlock(text="asdf")
     text_block.set_text("Ut enim ad minim veniam")
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "Ut enim ad minim veniam"
     })
 def test_text_block_set_font_type(self):
     text_block = TextBlock(text="asdf")
     text_block.set_font_type(FontType.DEFAULT)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "fontType": "default"
     })
 def test_text_block_set_spacing(self):
     text_block = TextBlock(text="asdf")
     text_block.set_spacing(SpacingStyle.EXTRA_LARGE)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "spacing": "extraLarge"
     })
 def test_text_block_set_color(self):
     text_block = TextBlock(text="asdf")
     text_block.set_color(Color.DEFAULT)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "color": "default"
     })
 def test_text_block_set_requires(self):
     text_block = TextBlock(text="asdf")
     text_block.set_requires(self.requires)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "requires": self.requires
     })
 def test_text_block_set_id(self):
     text_block = TextBlock(text="asdf")
     text_block.set_id("id_text_block_3")
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "id": "id_text_block_3"
     })
 def test_text_block_set_weight(self):
     text_block = TextBlock(text="asdf")
     text_block.set_weight(FontWeight.BOLDER)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "weight": "bolder"
     })
 def test_text_block_set_horizontal_alignment(self):
     text_block = TextBlock(text="asdf")
     text_block.set_horizontal_alignment(HorizontalAlignment.LEFT)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "horizontalAlignment": "left"
     })
 def test_text_block_set_size(self):
     text_block = TextBlock(text="asdf")
     text_block.set_size(FontSize.MEDIUM)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "size": "medium"
     })
 def test_text_block_set_max_lines(self):
     text_block = TextBlock(text="asdf")
     text_block.set_max_lines(1235)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "maxLines": 1235
     })
Beispiel #11
0
 def test_show_card(self):
     adaptive_card = AdaptiveCard()
     adaptive_card.add_elements(TextBlock(text="Sample text"))
     adaptive_card.add_actions(Submit(title="Vote"))
     show_card = ShowCard(card=adaptive_card,
                          tooltip="Etiam venenatis",
                          is_enabled=True,
                          mode=ActionMode.PRIMARY)
     self.assertDictEqual(
         show_card.as_data(), {
             "type": "Action.ShowCard",
             "card": {
                 "type": "AdaptiveCard",
                 "body": [{
                     "type": "TextBlock",
                     "text": "Sample text"
                 }],
                 "actions": [{
                     "type": "Action.Submit",
                     "title": "Vote"
                 }]
             },
             "tooltip": "Etiam venenatis",
             "mode": "primary",
             "isEnabled": True
         })
 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_text_block(self):
     text_block = TextBlock(text="Lorem ipsum dolor sit amet", color=Color.ATTENTION, font_type=FontType.MONOSPACE,
                            horizontal_alignment=HorizontalAlignment.CENTER, is_subtle=True, max_lines=32,
                            size=FontSize.LARGE, weight=FontWeight.LIGHTER, wrap=True, fallback=FallbackOption.DROP,
                            separator=True, spacing=SpacingStyle.LARGE, item_id="id_text_block", is_visible=True,
                            requires=self.requires)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "Lorem ipsum dolor sit amet",
         "color": "attention",
         "fontType": "monospace",
         "horizontalAlignment": "center",
         "isSubtle": True,
         "maxLines": 32,
         "size": "large",
         "weight": "lighter",
         "wrap": True,
         "fallback": "drop",
         "separator": True,
         "spacing": "large",
         "id": "id_text_block",
         "isVisible": True,
         "requires": self.requires
     })
Beispiel #14
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,
from django_actionable_messages.adaptive_card.containers import Column, ColumnSet, FactSet, Fact
from django_actionable_messages.adaptive_card.elements import TextBlock, Image
from django_actionable_messages.adaptive_card.inputs import DateInput, TextInput
from django_actionable_messages.adaptive_card.utils import (SCHEMA, FontSize,
                                                            FontWeight, Width,
                                                            ImageSize,
                                                            ImageStyle,
                                                            SpacingStyle)
"""
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",
 def test_text_block_set_wrap(self):
     text_block = TextBlock(text="asdf")
     text_block.set_wrap(False)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "wrap": False
     })
     text_block.set_wrap(True)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "wrap": True
     })
     text_block.set_wrap()
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "wrap": True
     })
from django_actionable_messages.adaptive_card.actions import Submit, ShowCard
from django_actionable_messages.adaptive_card.cards import AdaptiveCard
from django_actionable_messages.adaptive_card.containers import ImageSet
from django_actionable_messages.adaptive_card.elements import TextBlock, Image
from django_actionable_messages.adaptive_card.inputs import TextInput, ToggleInput, InputChoice, ChoiceSetInput
from django_actionable_messages.adaptive_card.utils import SCHEMA, FontSize, FontWeight

"""
https://adaptivecards.io/samples/FoodOrder.html
"""


adaptive_card1 = AdaptiveCard()
adaptive_card1.add_elements([
    TextBlock("How would you like your steak prepared?", size=FontSize.MEDIUM, wrap=True),
    ChoiceSetInput(
        item_id="SteakTemp",
        choices=[
            InputChoice("Rare", "rare"),
            InputChoice("Medium-rare", "medium-rare"),
            InputChoice("Well-done", "well-done")
        ]
    ),
    TextInput(item_id="SteakOther", is_multiline=True, placeholder="Any other preparation requests?")
])
adaptive_card1.add_actions(Submit(title="OK", data={"FoodChoice": "Steak"}))
adaptive_card2 = AdaptiveCard()
adaptive_card2.add_elements([
    TextBlock("Do you have any allergies?", size=FontSize.MEDIUM, wrap=True),
    ChoiceSetInput(
        item_id="ChickenAllergy",
Beispiel #18
0
from django_actionable_messages.adaptive_card.cards import AdaptiveCard
from django_actionable_messages.adaptive_card.elements import TextBlock
from django_actionable_messages.adaptive_card.inputs import InputChoice, ChoiceSetInput
from django_actionable_messages.adaptive_card.utils import SCHEMA, FontSize, FontWeight, SpacingStyle, ChoiceInputStyle
"""
https://adaptivecards.io/samples/CalendarReminder.html
"""

calendar_reminder = AdaptiveCard(version="1.0", schema=SCHEMA)
calendar_reminder.set_speak(
    "Your  meeting about \"Adaptive Card design session\" is starting at 12:30pm"
    "Do you want to snooze  or do you want to send a late notification to the attendees?"
)
calendar_reminder.add_elements(
    TextBlock("Adaptive Card design session",
              size=FontSize.LARGE,
              weight=FontWeight.BOLDER))
calendar_reminder.add_elements([
    TextBlock("Conf Room 112/3377 (10)", is_subtle=True),
    TextBlock("12:30 PM - 1:30 PM", is_subtle=True, spacing=SpacingStyle.NONE),
    TextBlock("Snooze for")
])
calendar_reminder.add_elements(
    ChoiceSetInput(item_id="snooze",
                   style=ChoiceInputStyle.COMPACT,
                   value="5",
                   choices=[
                       InputChoice("5 minutes", "5"),
                       InputChoice("15 minutes", "15"),
                       InputChoice("30 minutes", "30")
                   ]))
 def test_text_block_set_is_subtle(self):
     text_block = TextBlock(text="asdf")
     text_block.set_is_subtle(False)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "isSubtle": False
     })
     text_block.set_is_subtle(True)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "isSubtle": True
     })
     text_block.set_is_subtle()
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "isSubtle": True
     })
 def test_text_block_set_separator(self):
     text_block = TextBlock(text="asdf")
     text_block.set_separator(False)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "separator": False
     })
     text_block.set_separator(True)
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "separator": True
     })
     text_block.set_separator()
     self.assertDictEqual(text_block.as_data(), {
         "type": "TextBlock",
         "text": "asdf",
         "separator": True
     })
Beispiel #21
0
from django_actionable_messages.adaptive_card.actions import OpenUrl
from django_actionable_messages.adaptive_card.cards import AdaptiveCard
from django_actionable_messages.adaptive_card.containers import ColumnSet, Column
from django_actionable_messages.adaptive_card.elements import TextBlock, Image
from django_actionable_messages.adaptive_card.utils import SCHEMA, FontSize, FontWeight, SpacingStyle, ImageSize
"""
https://adaptivecards.io/samples/Restaurant.html
"""

restaurant = AdaptiveCard(version="1.0", schema=SCHEMA)
restaurant.add_elements([
    ColumnSet(columns=[
        Column(
            width=2,
            items=[
                TextBlock("Pizza"),
                TextBlock("Tom's Pie",
                          weight=FontWeight.BOLDER,
                          size=FontSize.EXTRA_LARGE,
                          spacing=SpacingStyle.NONE),
                TextBlock("4.2 ★★★☆ (93) · $$",
                          is_subtle=True,
                          spacing=SpacingStyle.NONE),
                TextBlock(
                    "**Matt H. said** \"I'm compelled to give this place 5 stars due to the number of times "
                    "I've chosen to eat here this past year!\"",
                    size=FontSize.SMALL,
                    wrap=True)
            ]),
        Column(width=1,
               items=[
Beispiel #22
0
    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(
                    "http://messagecardplayground.azurewebsites.net/assets/LocationBlue_B.png"
                )
            ],
                   width=Width.AUTO),
            Column(items=[