diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-18 20:21:56 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2023-10-18 21:18:37 +0200 |
commit | 2e5fdd068ad0ab0843be714bc7ac52316514103e (patch) | |
tree | 553838b612405261cea570bd5530ac82e620a75b /_pytest | |
parent | 27c8262f2a60ef1276869a1d4d5d43a0339a785d (diff) | |
download | wee-slack-2e5fdd068ad0ab0843be714bc7ac52316514103e.tar.gz |
Properly fix rendering of < and >
I tried to do a fix for this in commit 6478c141, but it only fixed
normal text, not e.g. code blocks and attachments. With this I think it
should be correct everywhere.
Fixes #908
Diffstat (limited to '_pytest')
-rw-r--r-- | _pytest/test_render_message.py | 50 | ||||
-rw-r--r-- | _pytest/test_unwrap_attachments.py | 126 |
2 files changed, 154 insertions, 22 deletions
diff --git a/_pytest/test_render_message.py b/_pytest/test_render_message.py index c14fbd4..12b654d 100644 --- a/_pytest/test_render_message.py +++ b/_pytest/test_render_message.py @@ -89,6 +89,56 @@ import wee_slack ), "render_emoji_as_string": "both", }, + { + "input_message": { + "blocks": [ + { + "type": "rich_text", + "block_id": "ASgLI", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + {"type": "text", "text": "<text> & "}, + { + "type": "link", + "url": "https://text.link?x=<x>&z=z", + }, + {"type": "text", "text": " "}, + { + "type": "text", + "text": "<code> & ", + "style": {"code": True}, + }, + { + "type": "link", + "url": "https://code.link?x=<x>&z=z", + "style": {"code": True}, + }, + {"type": "text", "text": "\n"}, + ], + }, + { + "type": "rich_text_preformatted", + "elements": [ + {"type": "text", "text": "<code block> & "}, + { + "type": "link", + "url": "https://codeblock.link?x=<x>&z=z", + }, + ], + "border": 0, + }, + ], + } + ], + }, + "rendered": ( + "<text> & https://text.link?x=<x>&z=z `<code> & https://code.link?x=<x>&z=z`\n" + "```\n<code block> & https://codeblock.link?x=<x>&z=z\n```" + ), + "render_emoji_as_string": "both", + }, ], ) def test_render_message(case, channel_general): diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py index 25ffd04..34d27de 100644 --- a/_pytest/test_unwrap_attachments.py +++ b/_pytest/test_unwrap_attachments.py @@ -77,28 +77,7 @@ import pytest } ] }, - "input_text_before": "http://link?a=1&b=2", - "output": "\n".join( - [ - "", - "| Title", - "| Attachment text", - ] - ), - }, - { - "input_message": { - "attachments": [ - { - "title": "Title", - "text": "Attachment text", - "title_link": "http://link?a=1&b=2", - "from_url": "http://link?a=1&b=2", - "image_url": "http://link?a=1&b=2", - } - ] - }, - "input_text_before": "http://link?a=1&b=2", + "input_text_before": "http://link?a=1&b=2", "output": "\n".join( [ "", @@ -460,6 +439,109 @@ import pytest ), "link_previews": False, }, + { + "input_message": { + "attachments": [ + { + "id": 1, + "ts": 1697480778, + "fallback": "title & <asd>", + "text": "text & <asd>", + "pretext": "pretext & <asd>", + "title": "title & <asd>", + "title_link": "https://title.link/?x=<x>&z=z", + "author_name": "author_name & <asd>", + "from_url": "https://from.url/?x=<x>&z=z", + "image_url": "https://image.url/?x=<x>&z=z", + "footer": "footer & <asd>", + "fields": [ + { + "value": "field value & <asd>", + "title": "field title & <asd>", + "short": False, + }, + { + "value": "field value mention <@U407ABLLW>", + "title": "field title mention <@U407ABLLW>", + "short": False, + }, + ], + }, + { + "id": 2, + "blocks": [ + { + "type": "rich_text", + "block_id": "IQm+Q", + "elements": [ + { + "type": "rich_text_preformatted", + "elements": [ + { + "type": "text", + "text": "block rich_text_preformatted & <asd>", + } + ], + } + ], + }, + { + "type": "rich_text", + "block_id": "a5bVo", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + { + "type": "text", + "text": "block rich_text_section & <asd> ", + }, + { + "type": "link", + "url": "https://block.link?x=<x>&z=z", + "style": {"code": True}, + }, + ], + } + ], + }, + { + "type": "rich_text", + "block_id": "FeChA", + "elements": [ + { + "type": "rich_text_section", + "elements": [ + {"type": "user", "user_id": "U407ABLLW"}, + {"type": "text", "text": ": <@ASD>"}, + ], + } + ], + }, + ], + "fallback": "[no preview available]", + }, + ] + }, + "input_text_before": "", + "output": "\n".join( + [ + "| pretext & <asd>", + "| author_name & <asd>: title & <asd> (https://title.link/?x=<x>&z=z)", + "| https://from.url/?x=<x>&z=z", + "| text & <asd>", + "| https://image.url/?x=<x>&z=z", + "| field title & <asd>: field value & <asd>", + "| field title mention <@U407ABLLW>: field value mention @alice", + "| footer & <asd> | Oct 16, 2023", + "| ```", + "| block rich_text_preformatted & <asd>", + "| ```", + "| block rich_text_section & <asd> `https://block.link?x=<x>&z=z`", + "| @alice: <@ASD>", + ] + ), + }, ), ) def test_unwrap_attachments(case, channel_general): |