Skip to content

Commit 217e4ea

Browse files
authored
Merge pull request #175 from StackStorm/add-pack-alias-test
Add a test for bad arguments to the pack alias
2 parents 2d6559f + 3d5c8d1 commit 217e4ea

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packs/chatops_tests/actions/test_aliases_with_slack.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,49 @@ def test_run_command_on_localhost(self):
245245
# Drain the event buffer
246246
self.client.rtm_read()
247247

248+
def test_run_command_on_localhost_with_bad_argument(self):
249+
post_message_response = self.client.api_call(
250+
"chat.postMessage",
251+
channel=self.channel,
252+
text="!pack get pack=example",
253+
as_user=True)
254+
255+
messages = []
256+
for i in range(self.WAIT_FOR_MESSAGES_TIMEOUT):
257+
if len(messages) >= 1:
258+
break
259+
time.sleep(1)
260+
261+
all_messages = self.client.rtm_read()
262+
263+
filtered_messages = filter(self.filter, all_messages)
264+
265+
if filtered_messages:
266+
messages.extend(filtered_messages)
267+
268+
self.assertEqual(1, len(messages))
269+
if len(messages) != 1:
270+
time.sleep(self.WAIT_FOR_MESSAGES_TIMEOUT)
271+
272+
# Test for response
273+
self.assertIsNotNone(messages[0].get('bot_id'))
274+
self.assertIsNotNone(messages[0].get('attachments'))
275+
self.assertGreater(len(messages[0]['attachments']), 0)
276+
self.assertIsNotNone(messages[0]['attachments'][0].get('color'))
277+
self.assertEqual(messages[0]['attachments'][0]['color'], 'F35A00')
278+
self.assertIsNotNone(messages[0]['attachments'][0].get('text'))
279+
280+
# Check the pretext
281+
msg_pretext = messages[0]['attachments'][0]['pretext']
282+
self.assertRegex(msg_pretext, r"<@{userid}>: I'm sorry, Dave. I'm afraid I can't do that. ".format(userid=self.userid))
283+
284+
# Test attachment
285+
msg_text = messages[0]['attachments'][0]['text']
286+
self.assertRegex(msg_text, r"Command \"pack get pack=example\" doesn't match format string \"pack get \{\{ pack \}\}\"")
287+
288+
# Drain the event buffer
289+
self.client.rtm_read()
290+
248291
def test_run_exact_command_on_localhost(self):
249292
post_message_response = self.client.api_call(
250293
"chat.postMessage",

0 commit comments

Comments
 (0)