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
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)
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)
def test_create_card_header_with_invalid_style(): with pytest.raises(ValueError): create_card_header("Title", "Subtitle", "http://server.com/image.png", "INVALID")
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
def test_create_card_header_with_invalid_image(): with pytest.raises(ValueError): create_card_header("Title", "Subtitle", None)
def test_create_card_header_with_invalid_title(): with pytest.raises(ValueError): create_card_header(None, "Subtitle", "http://server.com/image.png")