This repository has been archived by the owner on Jun 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some tests to verify the setting of the channel topic
- Loading branch information
1 parent
83d65f0
commit 6147f24
Showing
2 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import asynctest | ||
import json | ||
from asynctest.mock import patch | ||
from asynctest.mock import call | ||
|
||
|
||
class TestSetChannelTopic(asynctest.TestCase): | ||
|
||
def setUp(self): | ||
patcher1 = patch('charlesbot_rundeck.rundeck_lock.RundeckLock.seed_job_list') # NOQA | ||
self.addCleanup(patcher1.stop) | ||
self.mock_seed_job_list = patcher1.start() | ||
|
||
patcher2 = patch('charlesbot.slack.slack_connection.SlackConnection.api_call') # NOQA | ||
self.addCleanup(patcher2.stop) | ||
self.mock_api_call = patcher2.start() | ||
|
||
from charlesbot_rundeck.rundeck_lock import RundeckLock | ||
self.rd_lock = RundeckLock("token", | ||
"url", | ||
"channel", | ||
[]) | ||
|
||
def test_topic_channel_not_set(self): | ||
self.rd_lock.topic_channel = None | ||
yield from self.rd_lock.set_channel_topic(True) | ||
self.assertEqual(self.mock_api_call.mock_calls, []) | ||
|
||
def test_topic_channel_id_already_set(self): | ||
self.rd_lock.locked_by_user = "bob" | ||
self.rd_lock.topic_channel = "chan1" | ||
self.rd_lock.topic_channel_id = "C1234" | ||
yield from self.rd_lock.set_channel_topic(True) | ||
calls = [ | ||
call("channels.setTopic", | ||
channel="C1234", | ||
topic=":lock: Rundeck executions locked by @bob :lock:") | ||
] | ||
self.assertEqual(self.mock_api_call.mock_calls, calls) | ||
|
||
def test_topic_channel_not_found(self): | ||
channels = { | ||
"ok": True, | ||
"channels": [ | ||
{ | ||
"name": "chan1", | ||
}, | ||
{ | ||
"name": "chan2", | ||
}, | ||
{ | ||
"name": "chan3", | ||
}, | ||
] | ||
} | ||
self.rd_lock.locked_by_user = "bob" | ||
self.rd_lock.topic_channel = "chan4" | ||
self.mock_api_call.side_effect = [json.dumps(channels), None] | ||
yield from self.rd_lock.set_channel_topic(True) | ||
calls = [ | ||
call("channels.list", exclude_archived=1), | ||
] | ||
self.assertEqual(self.mock_api_call.mock_calls, calls) | ||
|
||
def test_topic_channel_found(self): | ||
channels = { | ||
"ok": True, | ||
"channels": [ | ||
{ | ||
"name": "chan1", | ||
"id": "C1", | ||
}, | ||
{ | ||
"name": "chan2", | ||
"id": "C2", | ||
}, | ||
{ | ||
"name": "chan3", | ||
"id": "C3", | ||
}, | ||
] | ||
} | ||
self.rd_lock.locked_by_user = "bob" | ||
self.rd_lock.topic_channel = "chan2" | ||
self.mock_api_call.side_effect = [json.dumps(channels), None] | ||
yield from self.rd_lock.set_channel_topic(False) | ||
calls = [ | ||
call("channels.list", exclude_archived=1), | ||
call("channels.setTopic", | ||
channel="C2", | ||
topic="") | ||
] | ||
self.assertEqual(self.mock_api_call.mock_calls, calls) |