aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-09-20 23:55:33 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-09-20 23:55:33 +0200
commitdb6b99fc17a1e37564723452963246a9e7a2b787 (patch)
treec05e1eef7219b193b85699c5422a1b05acb9af01
parent4556187df35b6bcbbff310ae68ac2ec4bfd9d8ad (diff)
downloadwee-slack-db6b99fc17a1e37564723452963246a9e7a2b787.tar.gz
Add a newline between attachments
-rw-r--r--_pytest/test_unwrap_attachments.py22
-rw-r--r--wee_slack.py8
2 files changed, 26 insertions, 4 deletions
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
index 8b22515..8e41662 100644
--- a/_pytest/test_unwrap_attachments.py
+++ b/_pytest/test_unwrap_attachments.py
@@ -121,6 +121,28 @@ import pytest
"Second field value",
]),
},
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'First attachment title',
+ 'text': 'First attachment text',
+ 'title_link': 'http://title.link.1',
+ 'from_url': 'http://from.url.1',
+ }, {
+ 'title': 'Second attachment title',
+ 'text': 'Second attachment text',
+ 'title_link': 'http://title.link.2',
+ 'from_url': 'http://from.url.2',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "First attachment title (http://title.link.1)",
+ "http://from.url.1",
+ "First attachment text",
+ "Second attachment title (http://title.link.2)",
+ "http://from.url.2",
+ "Second attachment text",
+ ]),
+ },
))
def test_unwrap_attachments(case):
result = wee_slack.unwrap_attachments(
diff --git a/wee_slack.py b/wee_slack.py
index 950117c..334a8ba 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2600,11 +2600,11 @@ def unhtmlescape(text):
def unwrap_attachments(message_json, text_before):
- attachment_text = ''
+ attachment_texts = []
a = message_json.get("attachments", None)
if a:
if text_before:
- attachment_text = '\n'
+ attachment_texts.append('')
for attachment in a:
# Attachments should be rendered roughly like:
#
@@ -2647,8 +2647,8 @@ def unwrap_attachments(message_json, text_before):
fallback = attachment.get("fallback", None)
if t == [] and fallback:
t.append(fallback)
- attachment_text += "\n".join([x.strip() for x in t if x])
- return attachment_text
+ attachment_texts.append("\n".join([x.strip() for x in t if x]))
+ return "\n".join(attachment_texts)
def resolve_ref(ref):