aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharlie Allom <yeled@github.com>2018-06-08 09:47:53 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2018-06-08 10:47:53 +0200
commit41b847ecc1978249052e1ef5c6dbb161f0dc5ca2 (patch)
tree8d4aef00dd13438867f34c2a192d7ec8edf7020c
parent6df61f330460316db2a72e770214b1ba82c3cb56 (diff)
downloadwee-slack-41b847ecc1978249052e1ef5c6dbb161f0dc5ca2.tar.gz
print `image_url` if it exists (#504)
* print `image_url` if it exists * add test for image_url * requirements.txt for pytest * fix requirements.txt * text before image_url * this isn’t required * README readability for development section thanks @trygveaa * README reorder for this development section
-rw-r--r--README.md7
-rw-r--r--_pytest/test_unwrap_attachments.py15
-rw-r--r--requirements.txt3
-rw-r--r--wee_slack.py5
4 files changed, 28 insertions, 2 deletions
diff --git a/README.md b/README.md
index 999f40f..4115414 100644
--- a/README.md
+++ b/README.md
@@ -288,10 +288,13 @@ Show channel name in hotlist after activity
/set weechat.look.hotlist_names_level 14
```
-Debugging
---------------
+Development
+-----------------
+
+To run the tests, create a virtualenv and pip install from the `requirements.txt`. Then `pytest` to run them locally.
Enable debug mode and change debug level (default 3, decrease to increase logging and vice versa):
+
```
/set plugins.var.python.slack.debug_mode on
/set plugins.var.python.slack.debug_level 2
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
index ee5bd8b..0839613 100644
--- a/_pytest/test_unwrap_attachments.py
+++ b/_pytest/test_unwrap_attachments.py
@@ -32,6 +32,21 @@ import pytest
'input_message': {'attachments': [{
'title': 'Title',
'text': 'Attachment text',
+ 'title_link': 'http://title.link',
+ 'image_url': 'http://image.url',
+ 'fallback': 'Fallback',
+ }]},
+ 'input_text_before': "",
+ 'output': "\n".join([
+ "Title (http://title.link)",
+ "Attachment text",
+ "http://image.url",
+ ]),
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'title': 'Title',
+ 'text': 'Attachment text',
'title_link': 'http://link?a=1&b=2',
'from_url': 'http://link?a=1&b=2',
}]},
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..d0d67bc
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,3 @@
+pytest
+mock
+websocket-client
diff --git a/wee_slack.py b/wee_slack.py
index 9262e7f..dae13b0 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2812,6 +2812,11 @@ def unwrap_attachments(message_json, text_before):
tx = re.sub(r' *\n[\n ]+', '\n', atext)
t.append(prepend_title_text + tx)
prepend_title_text = ''
+
+ image_url = attachment.get('image_url', '')
+ if image_url not in text_before_unescaped and image_url != title_link:
+ t.append(image_url)
+
fields = attachment.get("fields", None)
if fields:
for f in fields: