|
7 | 7 | from .provider import SlackProvider |
8 | 8 | from custom_slack_provider.slack import CustomSlackClient, SlackException |
9 | 9 | from django.core.management import call_command |
| 10 | +from |
10 | 11 |
|
11 | 12 |
|
12 | 13 | class SlackOAuth2Tests(OAuth2TestsMixin, TestCase): |
@@ -60,14 +61,37 @@ def test__make_slack_post_request(self, post): |
60 | 61 | mock_response.json.return_value = {'ok': False, |
61 | 62 | 'error': 'Slack Error'} |
62 | 63 | try: |
63 | | - client._make_slack_get_request(url='test') |
| 64 | + client._make_slack_post_request(url='test', data={}) |
64 | 65 | except SlackException as e: |
65 | 66 | self.assertTrue(isinstance(e, SlackException)) |
66 | 67 | self.assertEquals(e.message, 'Slack Error') |
67 | 68 |
|
68 | | - @patch('custom_slack_provider.slack.CustomSlackClient._make_slack_get_request') |
| 69 | + @patch('custom_slack_provider.slack.CustomSlackClient._make_slack_get_request') # noqa: 501 |
69 | 70 | def test_get_identity(self, _make_slack_get_request): |
70 | 71 | _make_slack_get_request.return_value = {'user': {'id': 1}} |
71 | 72 | client = CustomSlackClient(self.token) |
72 | 73 | response = client.get_identity() |
73 | 74 | self.assertEqual(response['user']['id'], 1) |
| 75 | + |
| 76 | + def test__extract_userid_from_username(self): |
| 77 | + valid_username = 'US123123_T123123' |
| 78 | + invalid_username = 'bob@bob.com' |
| 79 | + client = CustomSlackClient(self.token) |
| 80 | + userid = client._extract_userid_from_username(valid_username) |
| 81 | + self.assertEqual(userid, 'US123123') |
| 82 | + try: |
| 83 | + userid = client._extract_userid_from_username(invalid_username) |
| 84 | + except SlackException as e: |
| 85 | + self.assertTrue(isinstance(e, SlackException)) |
| 86 | + self.assertEquals(e.message, 'Error adding user to channel') |
| 87 | + |
| 88 | + @patch('custom_slack_provider.slack.CustomSlackClient._make_slack_post_request') # noqa: 501 |
| 89 | + def test_add_user_to_slack_channel(self, _make_slack_post_request): |
| 90 | + _make_slack_post_request.return_value = { |
| 91 | + 'ok': True, |
| 92 | + 'channel': {'id': 'CH123123'} |
| 93 | + } |
| 94 | + client = CustomSlackClient(self.token) |
| 95 | + response = client.add_user_to_slack_channel(username='UA123123_T15666', |
| 96 | + channel_id='CH123123') |
| 97 | + self.assertEqual(response['channel']['id'], 'CH123123') |
0 commit comments