forked from os/slacker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_channels.py
52 lines (41 loc) · 1.26 KB
/
test_channels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import unittest
from mock import patch, Mock
from slacker import Channels
class TestUtils(unittest.TestCase):
@patch('slacker.requests')
def test_get_channel_id(self, mock_requests):
text = {
'ok': 'true',
'channels': [
{'name': 'general', 'id': 'C111'},
{'name': 'random', 'id': 'C222'}
]
}
json_to_text = json.dumps(text)
mock_requests.get.return_value = Mock(
status_code=200, text=json_to_text,
)
channels = Channels(token='aaa')
self.assertEqual(
'C111', channels.get_channel_id('general')
)
@patch('slacker.requests')
def test_get_channel_id_without_channel(self, mock_requests):
text = {
'ok': 'true',
'channels': [
{'name': 'general', 'id': 'C111'},
{'name': 'random', 'id': 'C222'}
]
}
json_to_text = json.dumps(text)
mock_requests.get.return_value = Mock(
status_code=200, text=json_to_text,
)
channels = Channels(token='aaa')
self.assertEqual(
None, channels.get_channel_id('fake_group')
)