aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-09-20 23:38:55 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-09-20 23:52:45 +0200
commitdeb9f11ad36cfebbee5b4f0783108433f67f6b56 (patch)
tree63221ea3b4d9fc070b26dce4c386fda4546a9933
parent2f43d1b6466c74e8774e2833214f847eb559f15a (diff)
downloadwee-slack-deb9f11ad36cfebbee5b4f0783108433f67f6b56.tar.gz
test: Add tests for unwrap_attachments
-rw-r--r--_pytest/test_unwrap_attachments.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
new file mode 100644
index 0000000..e70256e
--- /dev/null
+++ b/_pytest/test_unwrap_attachments.py
@@ -0,0 +1,115 @@
+import wee_slack
+import pytest
+
+
+@pytest.mark.parametrize('case', (
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ }]},
+ 'input_text_before': "Text before",
+ 'output': "\n".join([
+ "",
+ "Title",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'text': 'Attachment text',
+ 'title_link': 'http://title.link',
+ 'from_url': 'http://from.url',
+ 'fallback': 'Fallback',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "Title (http://title.link)",
+ "http://from.url",
+ "Attachment text",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'text': 'Attachment text',
+ 'title_link': 'http://link',
+ 'from_url': 'http://link',
+ }]},
+ 'input_text_before': "http://link",
+ 'output': "\n".join([
+ "",
+ "Title",
+ "Attachment text",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'text': 'Attachment text\n\n\nWith multiple lines',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "Title",
+ "Attachment text\nWith multiple lines",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'author_name': 'Author',
+ 'pretext': 'Pretext',
+ 'text': 'Attachment text',
+ 'title_link': 'http://title.link',
+ 'from_url': 'http://from.url',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "Pretext",
+ "Author: Title (http://title.link)",
+ "http://from.url",
+ "Attachment text",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'author_name': 'Author',
+ 'text': 'Attachment text',
+ 'title_link': 'http://title.link',
+ 'from_url': 'http://from.url',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "http://from.url",
+ "Author: Attachment text",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'fallback': 'Fallback',
+ }]},
+ 'input_text_before': "",
+ 'output': "Fallback",
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'fields': [{
+ 'title': 'First field title',
+ 'value': 'First field value',
+ }, {
+ 'title': '',
+ 'value': 'Second field value',
+ }],
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "Title",
+ "First field title First field value",
+ "Second field value",
+ ]),
+ },
+))
+def test_unwrap_attachments(case):
+ result = wee_slack.unwrap_attachments(
+ case['input_message'], case['input_text_before'])
+ assert result == case['output']