def test_start_group(): e = EXPECTED_TITLE e.update(EXPECTED_GROUP) section = CardSection() section.set_title(e["title"]) section.start_group() assert section.json_payload == json.dumps(e)
def test_texts(): e = EXPECTED_TEXT section = CardSection() section.set_text(e["text"]) assert section.json_payload == json.dumps(e) section = CardSection(text=e["text"]) assert section.json_payload == json.dumps(e)
def test_title(): e = EXPECTED_TITLE section = CardSection() section.set_title(e["title"]) assert section.json_payload == json.dumps(e) section = CardSection(title=e["title"]) assert section.json_payload == json.dumps(e)
def test_sections(): e = _get_exp_card() e.update(EXP_SECTIONS) card = MessageCard() s = CardSection(title=EXP_SECTIONS["sections"][0]["title"]) card.set_sections(s) assert card.json_payload == json.dumps(e) card = MessageCard() card.add_section(s) assert card.json_payload == json.dumps(e) card = MessageCard(sections=s) assert card.json_payload == json.dumps(e)
def test_potential_actions(): e = EXPECTED_ACTION section = CardSection() with pytest.raises(TypeError): section.add_potential_action(Fact("a", "b")) action = HttpPostAction( name=e["potentialAction"][0]["name"], target=e["potentialAction"][0]["target"] ) section.add_potential_action(action) assert section.json_payload == json.dumps(e)
def test_facts(): e = EXPECTED_FACTS fact_dict = OrderedDict() for f in e["facts"]: fact_dict[f["name"]] = f["value"] section = CardSection() section.set_facts(fact_dict) assert section.json_payload == json.dumps(e) section = CardSection() section.add_facts(fact_dict) assert section.json_payload == json.dumps(e) section = CardSection() for fact in e["facts"]: section.add_fact(fact["name"], fact["value"]) assert section.json_payload == json.dumps(e) section = CardSection(facts=fact_dict) assert section.json_payload == json.dumps(e)
def test_activity(): e = EXPECTED_ACTIVITY section = CardSection() section.set_activity( title=e["activityTitle"], subtitle=e["activitySubtitle"], image_url=e["activityImage"], ) assert section.json_payload == json.dumps(e) section = CardSection() section.set_activity_title(e["activityTitle"]) section.set_activity_subtitle(e["activitySubtitle"]) section.set_activity_image(e["activityImage"]) assert section.json_payload == json.dumps(e) section = CardSection( activity_title=e["activityTitle"], activity_subtitle=e["activitySubtitle"], activity_image=e["activityImage"], ) assert section.json_payload == json.dumps(e)
def test_total(): e = EXPECTED_ACTIVITY e.update(EXPECTED_TITLE) e.update(EXPECTED_FACTS) e.update(EXPECTED_TEXT) e.update(EXPECTED_HERO) section = CardSection() section = CardSection(title=e["title"]) section.set_activity( title=e["activityTitle"], subtitle=e["activitySubtitle"], image_url=e["activityImage"], ) for fact in e["facts"]: section.add_fact(fact["name"], fact["value"]) section.set_text(e["text"]) section.set_hero_image({e["heroImage"]["title"]: e["heroImage"]["image"]}) section.json_payload == json.dumps(e)
def test_hero_image(): e = EXPECTED_HERO image = ImageObject(image=e["heroImage"]["image"], title=e["heroImage"]["title"]) section = CardSection() section.set_hero_image(image) assert section.json_payload == json.dumps(e) section = CardSection() section.set_hero_image({e["heroImage"]["title"]: e["heroImage"]["image"]}) assert section.json_payload == json.dumps(e) section = CardSection() section.set_hero_image(e["heroImage"]["image"]) section["hero_image"].set_title(e["heroImage"]["title"]) assert section.json_payload == json.dumps(e) section = CardSection(hero_image={e["heroImage"]["title"]: e["heroImage"]["image"]}) assert section.json_payload == json.dumps(e)
def test_all(): """Replicate example from https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/cards/cards-format#formatting-sample-for-html-connector-cards """ card = MessageCard(summary="Summary", title="Connector Card HTML formatting") sections = [] sections.append(CardSection(text=" ".join(("This is some", bold("bold"), "text")))) sections.append( CardSection(text=" ".join(("This is some", italic("italic"), "text"))) ) sections.append( CardSection( text=" ".join(("This is some", strikethrough("strikethrough"), "text")) ) ) sections.append( CardSection( text="\r".join( ( header("Header 1", level=1), header("Header 2", level=2), header("Header 3", level=3), ) ) ) ) sections.append(CardSection(text="bullet list " + unordered_list(["text", "text"]))) sections.append(CardSection(text="ordered list " + ordered_list(["text", "text"]))) sections.append( CardSection(text="hyperlink " + link("Bing", "https://www.bing.com/")) ) sections.append( CardSection( text="embedded image " + img("http://aka.ms/Fo983c", "Duck on a rock") ) ) sections.append(CardSection(text="preformatted text " + preformatted("text"))) sections.append( CardSection(text="Paragraphs " + paragraph("Line a") + paragraph("Line b")) ) sections.append(CardSection(text=blockquote("Blockquote text"))) card.set_sections(sections) assert ( card.get_payload("json", indent=4) == """{ "@type": "MessageCard", "@context": "https://schema.org/extensions", "summary": "Summary", "title": "Connector Card HTML formatting", "sections": [ { "text": "This is some <strong>bold</strong> text" }, { "text": "This is some <em>italic</em> text" }, { "text": "This is some <strike>strikethrough</strike> text" }, { "text": "<h1>Header 1</h1>\\r<h2>Header 2</h2>\\r<h3>Header 3</h3>" }, { "text": "bullet list <ul><li>text</li><li>text</li></ul>" }, { "text": "ordered list <ol><li>text</li><li>text</li></ol>" }, { "text": "hyperlink <a href=\\"https://www.bing.com/\\">Bing</a>" }, { "text": "embedded image <img src=\\"http://aka.ms/Fo983c\\" alt=\\"Duck on a rock\\"></img>" }, { "text": "preformatted text <pre>text</pre>" }, { "text": "Paragraphs <p>Line a</p><p>Line b</p>" }, { "text": "<blockquote>Blockquote text</blockquote>" } ] }""" )