def test_http_post_set_name(self): action = HttpPOST("Send", URL) action.set_name("Praesent") self.assertDictEqual(action.as_data(), { "@type": "HttpPOST", "name": "Praesent", "target": URL })
def test_http_post_set_target(self): action = HttpPOST("Send", URL) action.set_target("https://www.sample.domain.com") self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Send", "target": "https://www.sample.domain.com" })
def test_http_post_set_body_content_type(self): action = HttpPOST("Post", URL) action.set_body_content_type("content_type") self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Post", "target": URL, "bodyContentType": "content_type" })
def test_http_post_set_body(self): action = HttpPOST("Post", URL) action.set_body("sample body") self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Post", "target": URL, "body": "sample body" })
def test_section_add_potential_actions(self): section = Section() actions = [ HttpPOST("Open", target=URL), HttpPOST("Click", target="www.example.com", body="asdf") ] section.add_potential_actions(actions) self.assertDictEqual( section.as_data(), { "potentialAction": [{ "@type": "HttpPOST", "name": "Open", "target": URL }, { "@type": "HttpPOST", "name": "Click", "target": "www.example.com", "body": "asdf" }] }) action = OpenUri("View", targets=[ ActionTarget(OSType.IOS, "http://www.example.com/"), ]) section.add_potential_actions(action) self.assertDictEqual( section.as_data(), { "potentialAction": [{ "@type": "HttpPOST", "name": "Open", "target": URL }, { "@type": "HttpPOST", "name": "Click", "target": "www.example.com", "body": "asdf" }, { "@type": "OpenUri", "name": "View", "targets": [{ "os": "iOS", "uri": "http://www.example.com/" }] }] })
def test_http_post(self): action = HttpPOST("Send", URL, headers=[ Header("Content-Length", "42"), ], body="qwerty", body_content_type="content_type") self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [{ "name": "Content-Length", "value": "42" }], "body": "qwerty", "bodyContentType": "content_type" })
def test_http_post_add_headers(self): action = HttpPOST("Send", URL) action.add_headers([ Header("Transfer-Encoding", "chunked"), Header("Proxy-Authenticate", "Basic") ]) self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [ { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Proxy-Authenticate", "value": "Basic" }, ] }) action.add_headers(Header("Trailer", "Expires")) self.assertDictEqual( action.as_data(), { "@type": "HttpPOST", "name": "Send", "target": URL, "headers": [{ "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Proxy-Authenticate", "value": "Basic" }, { "name": "Trailer", "value": "Expires" }] })
def test_message_card_add_actions(self): message_card = MessageCard(auto_correlation_id=False) message_card.add_actions([ OpenUri("Click", targets=[ ActionTarget(OSType.DEFAULT, URL), ]), HttpPOST("Post", URL, headers=[ Header("Content-Length", 11), ], body="quis nostrud exercitation ullamco", body_content_type="content_type") ]) self.assertDictEqual( message_card.payload, { "@type": "MessageCard", "@context": "https://schema.org/extensions", "potentialAction": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "default", "uri": URL }] }, { "@type": "HttpPOST", "name": "Post", "target": URL, "headers": [{ "name": "Content-Length", "value": 11 }], "body": "quis nostrud exercitation ullamco", "bodyContentType": "content_type" }] }) message_card.add_actions( OpenUri("View", targets=[ ActionTarget(OSType.DEFAULT, URL), ])) self.assertDictEqual( message_card.payload, { "@type": "MessageCard", "@context": "https://schema.org/extensions", "potentialAction": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "default", "uri": URL }] }, { "@type": "HttpPOST", "name": "Post", "target": URL, "headers": [{ "name": "Content-Length", "value": 11 }], "body": "quis nostrud exercitation ullamco", "bodyContentType": "content_type" }, { "@type": "OpenUri", "name": "View", "targets": [{ "os": "default", "uri": URL }] }] })
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)
""" issue_opened = MessageCard( title="Issue opened: \"Push notifications not working\"", summary="Issue 176715375", theme_color="0078D7") issue_opened.add_sections( Section( activity_title="Miguel Garcie", activity_subtitle="9/13/2016, 11:46am", activity_image= "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg", text= "There is a problem with Push notifications, they don't seem to be picked up by the connector.", facts=[ Fact("Repository:", "mgarcia\\test"), Fact("Issue #:", "176715375") ])) issue_opened.add_actions([ ActionCard(name="Add a comment", inputs=[ TextInput(input_id="comment", title="Enter a comment", is_multiline=True) ], actions=[HttpPOST("OK", target="http://...")]), HttpPOST("Close", target="http://..."), OpenUri("View in Github", targets=[ActionTarget(OSType.DEFAULT, "http://...")]) ])
Section( activity_title="Miguel Garcia", activity_subtitle="9/13/2016, 3:34pm", activity_image= "https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg", facts=[ Fact("Board:", "Name of board"), Fact("List:", "Name of list"), Fact("Assigned to:", "(none)"), Fact("Due date:", "(none)") ]) ]) trello_card.add_actions([ ActionCard(name="Set due date", inputs=[DateInput(input_id="dueDate", title="select a date")], actions=[HttpPOST("OK", target="http://...")]), ActionCard(name="Move", inputs=[ MultiChoiceInput(input_id="move", title="Pick a list", choices=[ InputChoice("List 1", "l1"), InputChoice("List 2", "l2") ]) ], actions=[HttpPOST("OK", target="http://...")]), ActionCard(name="Add a comment", inputs=[ TextInput(input_id="comment", is_multiline=True, title="Enter your comment")
def test_action_card_add_actions(self): action_card = ActionCard("Actions") action_card.add_actions([ OpenUri("Click", targets=[ActionTarget(OSType.IOS, URL)]), HttpPOST("Post", URL, headers=[Header("Cache-Control", "no-cache")], body="sample", body_content_type="zxcv") ]) self.assertDictEqual( action_card.as_data(), { "@type": "ActionCard", "name": "Actions", "actions": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "iOS", "uri": URL }] }, { "@type": "HttpPOST", "name": "Post", "target": URL, "headers": [{ "name": "Cache-Control", "value": "no-cache" }], "body": "sample", "bodyContentType": "zxcv" }] }) action_card.add_actions( OpenUri("View", targets=[ActionTarget(OSType.ANDROID, URL)])) self.assertDictEqual( action_card.as_data(), { "@type": "ActionCard", "name": "Actions", "actions": [{ "@type": "OpenUri", "name": "Click", "targets": [{ "os": "iOS", "uri": URL }] }, { "@type": "HttpPOST", "name": "Post", "target": URL, "headers": [{ "name": "Cache-Control", "value": "no-cache" }], "body": "sample", "bodyContentType": "zxcv" }, { "@type": "OpenUri", "name": "View", "targets": [{ "os": "android", "uri": URL }] }] })
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://...", is_primary=True) ]) ]), Section(activity_title="**Streak: 0** surveys in a row", activity_subtitle="Survey expires in 15 days on 4/6/2017") ])
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( name="Approve", inputs=[ TextInput(input_id="comment", is_multiline=True, title="Reason (optional)") ], actions=[ HttpPOST("OK", target="http://...") ] ), ActionCard( name="Reject", inputs=[ TextInput(input_id="comment", is_multiline=True, title="Reason (optional)") ], actions=[ HttpPOST("OK", target="http://...") ] ) ] ), Section( start_group=True,