示例#1
0
def test_create_card_with_header():
    widgets = [
        create_card_paragraph("Hello"),
        create_card_image("http://server.com/image.png"),
    ]

    header = create_card_header("Title", "Subtitle",
                                "http://server.com/header.png")

    expected = {
        "header": {
            "title": "Title",
            "subtitle": "Subtitle",
            "imageUrl": "http://server.com/header.png",
            "imageStyle": "IMAGE",
        },
        "sections": [{
            "widgets": [
                {
                    "textParagraph": {
                        "text": "Hello"
                    }
                },
                {
                    "image": {
                        "imageUrl": "http://server.com/image.png"
                    }
                },
            ]
        }],
    }

    assert create_card(widgets, header=header) == expected
示例#2
0
def test_create_card_header_with_default_style():
    expected = {
        "header": {
            "title": "Title",
            "subtitle": "Subtitle",
            "imageUrl": "http://server.com/image.png",
            "imageStyle": "IMAGE",
        }
    }

    assert (create_card_header("Title", "Subtitle",
                               "http://server.com/image.png") == expected)
示例#3
0
def test_create_card_header_with_avatar_style():
    expected = {
        "header": {
            "title": "Title",
            "subtitle": "Subtitle",
            "imageUrl": "http://server.com/image.png",
            "imageStyle": "AVATAR",
        }
    }

    assert (create_card_header("Title", "Subtitle",
                               "http://server.com/image.png",
                               "AVATAR") == expected)
示例#4
0
def test_create_card_header_with_invalid_style():
    with pytest.raises(ValueError):
        create_card_header("Title", "Subtitle", "http://server.com/image.png",
                           "INVALID")
示例#5
0
def test_create_cards_response_with_update_message():
    header = create_card_header("Title", "Subtitle",
                                "http://server.com/header.png")

    widgets = [
        create_card_paragraph("Hello"),
        create_card_image("http://server.com/image.png"),
    ]

    card1 = create_card(widgets, header=header)

    card2 = create_card([
        create_card_paragraph("World"),
        create_card_key_value("Label", "Content")
    ])

    expected = {
        "actionResponse": {
            "type": "UPDATE_MESSAGE"
        },
        "cards": [
            {
                "header": {
                    "title": "Title",
                    "subtitle": "Subtitle",
                    "imageUrl": "http://server.com/header.png",
                    "imageStyle": "IMAGE",
                },
                "sections": [{
                    "widgets": [
                        {
                            "textParagraph": {
                                "text": "Hello"
                            }
                        },
                        {
                            "image": {
                                "imageUrl": "http://server.com/image.png"
                            }
                        },
                    ]
                }],
            },
            {
                "sections": [{
                    "widgets": [
                        {
                            "textParagraph": {
                                "text": "World"
                            }
                        },
                        {
                            "keyValue": {
                                "content": "Content",
                                "topLabel": "Label"
                            }
                        },
                    ]
                }]
            },
        ],
    }

    assert create_cards_response([card1, card2],
                                 update_message=True) == expected
示例#6
0
def test_create_card_header_with_invalid_image():
    with pytest.raises(ValueError):
        create_card_header("Title", "Subtitle", None)
示例#7
0
def test_create_card_header_with_invalid_title():
    with pytest.raises(ValueError):
        create_card_header(None, "Subtitle", "http://server.com/image.png")