def test_hero_image(self): url = "{}image2.jpeg".format(URL) hero_image = HeroImage(url, title="Sample image") self.assertDictEqual(hero_image.as_data(), { "image": url, "title": "Sample image" })
def test_section_set_hero_image(self): section = Section() section.set_hero_image(HeroImage(URL, "Test")) self.assertDictEqual(section.as_data(), {"heroImage": { "image": URL, "title": "Test" }})
def test_hero_image_set_title(self): url = "{}image.jpeg".format(URL) hero_image = HeroImage(url) hero_image.set_title("Curabitur") self.assertDictEqual(hero_image.as_data(), { "image": url, "title": "Curabitur" })
def test_hero_imageset_url(self): url = "{}image2.jpeg".format(URL) hero_image = HeroImage(url, title="Sample image") hero_image.set_url("www.asdf.com") self.assertDictEqual(hero_image.as_data(), { "image": "www.asdf.com", "title": "Sample image" })
def test_section(self): hero_image = HeroImage("https://www.example.com/image.png", "Image") facts = [Fact("First name", "John"), Fact("Last name", "Johnson")] actions = [ OpenUri("Open", targets=[ ActionTarget(OSType.DEFAULT, "https://www.sample.com/"), ]), ] section = Section(start_group=True, title="Section title", text="Duis aute irure dolor", activity_image=URL, activity_title="Activity", activity_subtitle="sample subtitle", activity_text="asdf", hero_image=hero_image, facts=facts, actions=actions) self.assertDictEqual( section.as_data(), { "startGroup": True, "title": "Section title", "text": "Duis aute irure dolor", "activityImage": URL, "activityTitle": "Activity", "activitySubtitle": "sample subtitle", "activityText": "asdf", "heroImage": { "image": "https://www.example.com/image.png", "title": "Image" }, "facts": [{ "name": "First name", "value": "John" }, { "name": "Last name", "value": "Johnson" }], "potentialAction": [{ "@type": "OpenUri", "name": "Open", "targets": [{ "os": "default", "uri": "https://www.sample.com/" }] }] })
def test_message_card_add_sections(self): hero_image = HeroImage("www.zxcv.com", title="image2") fact1, fact2 = Fact("Value", "normal"), Fact("Lorem", "ipsum") action1 = OpenUri("View", targets=[ ActionTarget(OSType.ANDROID, "http://www.android.com/"), ]) action2 = HttpPOST("Send", URL, headers=[ Header("Content-Length", 16), ], body="post body", body_content_type="content type") action3 = OpenUri("Click", targets=[ ActionTarget(OSType.DEFAULT, "http://www.example.com/"), ]) section1 = Section(title="Sample section", activity_image="www.example.com", activity_title="Activity title", activity_subtitle="activity subtitle", activity_text="zxcv", hero_image=hero_image, facts=[fact1, fact2], actions=[action1, action2]) section2 = Section(title="Section 9", activity_image="www.section.com", activity_title="Activity", activity_subtitle="activity qwer", activity_text="asdf", hero_image=hero_image, facts=[ fact1, ], actions=[ action3, ]) section3 = Section(title="Section 3", activity_image="www.section3.com", activity_title="Activity", activity_subtitle="activity zxcv", activity_text="zxcv", hero_image=hero_image, facts=[ fact2, ], actions=[ action1, ]) message_card = MessageCard(auto_correlation_id=False) message_card.add_sections([section1, section2]) self.assertDictEqual( message_card.payload, { "@type": "MessageCard", "@context": "https://schema.org/extensions", "sections": [{ "title": "Sample section", "activityImage": "www.example.com", "activityTitle": "Activity title", "activitySubtitle": "activity subtitle", "activityText": "zxcv", "heroImage": { "image": "www.zxcv.com", "title": "image2" }, "facts": [{ "name": "Value", "value": "normal" }, { "name": "Lorem", "value": "ipsum" }], "potentialAction": [ { "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }, { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [{ "name": "Content-Length", "value": 16 }], "body": "post body", "bodyContentType": "content type" } ] }, { "title": "Section 9", "activityImage": "www.section.com", "activityTitle": "Activity", "activitySubtitle": "activity qwer", "activityText": "asdf", "heroImage": { "image": "www.zxcv.com", "title": "image2" }, "facts": [{ "name": "Value", "value": "normal" }], "potentialAction": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "default", "uri": "http://www.example.com/" }] }] }] }) message_card.add_sections(section3) self.assertDictEqual( message_card.payload, { "@type": "MessageCard", "@context": "https://schema.org/extensions", "sections": [{ "title": "Sample section", "activityImage": "www.example.com", "activityTitle": "Activity title", "activitySubtitle": "activity subtitle", "activityText": "zxcv", "heroImage": { "image": "www.zxcv.com", "title": "image2" }, "facts": [{ "name": "Value", "value": "normal" }, { "name": "Lorem", "value": "ipsum" }], "potentialAction": [ { "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }, { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [{ "name": "Content-Length", "value": 16 }], "body": "post body", "bodyContentType": "content type" } ] }, { "title": "Section 9", "activityImage": "www.section.com", "activityTitle": "Activity", "activitySubtitle": "activity qwer", "activityText": "asdf", "heroImage": { "image": "www.zxcv.com", "title": "image2" }, "facts": [{ "name": "Value", "value": "normal" }], "potentialAction": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "default", "uri": "http://www.example.com/" }] }] }, { "title": "Section 3", "activityImage": "www.section3.com", "activityTitle": "Activity", "activitySubtitle": "activity zxcv", "activityText": "zxcv", "heroImage": { "image": "www.zxcv.com", "title": "image2" }, "facts": [{ "name": "Lorem", "value": "ipsum" }], "potentialAction": [{ "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }] }] })
def test_message_card(self): url1, url2 = "https://www.example.com", "www.sample.com" hero_image1, hero_image2 = HeroImage( "www.sample.com", "image1"), HeroImage("www.asdf.com", title="image2") fact1, fact2 = Fact("Value", "5"), Fact("Name", "lorem") action1 = OpenUri("View", targets=[ ActionTarget(OSType.ANDROID, "http://www.android.com/"), ]) action2 = HttpPOST("Send", URL, headers=[ Header("Content-Length", 128), ], body="post body", body_content_type="content type") action3 = InvokeAddInCommand("Command", "id_cmd", "show", initialization_context={ "parameter1": 1, "parameter2": "blah" }) inputs = [ TextInput(input_id="id_text", max_length=128, is_multiline=True, is_required=True), ] actions = [ OpenUri("Open", targets=[ ActionTarget(OSType.WINDOWS, URL), ]), ] action4 = ActionCard("Action card", inputs=inputs, actions=actions) section1 = Section(title="Section first", activity_image=url1, activity_title="Activity 1", activity_subtitle="activity subtitle", activity_text="asdf", hero_image=hero_image1, facts=[fact1, fact2], actions=[action1, action3]) section2 = Section(start_group=False, title="Section second", activity_image=url2, activity_title="Activity 2", activity_subtitle="sample subtitle", activity_text="zxcv", hero_image=hero_image2, facts=[ fact2, ], actions=[action2, action1, action4]) correlation_id = str(uuid.uuid4()) message_card = MessageCard(title="Message card", text="asdf", summary="sample summary", originator="asdf", theme_color="0faabbff", correlation_id=correlation_id, auto_correlation_id=False, expected_actors=["*****@*****.**", "*****@*****.**"], hide_original_body=True, sections=[section1, section2], actions=[ action1, ]) self.assertDictEqual( message_card.payload, { "@type": "MessageCard", "@context": "https://schema.org/extensions", "title": "Message card", "text": "asdf", "summary": "sample summary", "themeColor": "0faabbff", "correlationId": correlation_id, "expectedActors": ["*****@*****.**", "*****@*****.**"], "hideOriginalBody": True, "originator": "asdf", "sections": [{ "title": "Section first", "activityImage": url1, "activityTitle": "Activity 1", "activitySubtitle": "activity subtitle", "activityText": "asdf", "heroImage": { "image": "www.sample.com", "title": "image1" }, "facts": [{ "name": "Value", "value": "5" }, { "name": "Name", "value": "lorem" }], "potentialAction": [{ "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }, { "@type": "InvokeAddInCommand", "name": "Command", "addInId": "id_cmd", "desktopCommandId": "show", "initializationContext": { "parameter1": 1, "parameter2": "blah" } }] }, { "title": "Section second", "activityImage": url2, "activityTitle": "Activity 2", "activitySubtitle": "sample subtitle", "activityText": "zxcv", "heroImage": { "image": "www.asdf.com", "title": "image2" }, "facts": [{ "name": "Name", "value": "lorem" }], "potentialAction": [ { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [{ "name": "Content-Length", "value": 128 }], "body": "post body", "bodyContentType": "content type" }, { "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }, { "@type": "ActionCard", "name": "Action card", "inputs": [{ "@type": "TextInput", "id": "id_text", "isRequired": True, "isMultiline": True, "maxLength": 128 }], "actions": [{ "@type": "OpenUri", "name": "Open", "targets": [{ "os": "windows", "uri": URL }] }] } ] }], "potentialAction": [{ "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": "http://www.android.com/" }] }] }) self.assertDictEqual(json.loads(message_card.json_payload), message_card.payload) self.assertIn("application/ld+json", message_card.html_payload)
from django_actionable_messages.message_card.actions import HttpPOST, ActionCard from django_actionable_messages.message_card.cards import MessageCard from django_actionable_messages.message_card.elements import HeroImage from django_actionable_messages.message_card.inputs import TextInput from django_actionable_messages.message_card.sections import Section """ TINYPulse - engaged https://messagecardplayground.azurewebsites.net/ """ tiny_pulse = MessageCard(summary="Poll: What do you love about your job?", theme_color="E81123") tiny_pulse.add_sections([ HeroImage( "https://messagecardplayground.azurewebsites.net/assets/TINYPulseEngageBanner.png" ), Section( start_group=True, activity_title="*What do you love about your job?**", activity_text= "It can be nothing, everything, and anything in between. Sharing is caring.", actions=[ ActionCard(name="Yes", inputs=[ TextInput(input_id="comment", is_multiline=True, title="Feel free to elaborate") ], actions=[ HttpPOST("Answer anonymously", target="http://...",
from django_actionable_messages.message_card.actions import HttpPOST, ActionCard from django_actionable_messages.message_card.cards import MessageCard from django_actionable_messages.message_card.elements import Fact, HeroImage from django_actionable_messages.message_card.inputs import TextInput from django_actionable_messages.message_card.sections import Section """ Microsoft - flow approval https://messagecardplayground.azurewebsites.net/ """ flow_approval = MessageCard(summary="This is the summary property", theme_color="0075FF") flow_approval.add_sections([ HeroImage("https://messagecardplayground.azurewebsites.net/assets/FlowLogo.png"), Section( start_group=True, title="**Pending approval**", activity_image="https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg", activity_title="Requested by **Miguel Garcia**", activity_subtitle="*****@*****.**", facts=[ Fact("Date submitted:", "06/27/2017, 2:44 PM"), Fact("Details:", "Please approve the awesome changes I made to this fantastic document."), Fact("Link:", "[Link to the awesome document.pptx](https://awesomedocument)"), ] ), Section( actions=[ ActionCard(