|
|
@@ -23,6 +23,7 @@ import sys
|
|
|
from nose.tools import assert_equal, assert_true
|
|
|
from django.test import TestCase, Client
|
|
|
from desktop.lib.botserver.views import *
|
|
|
+from desktop import conf
|
|
|
|
|
|
if sys.version_info[0] > 2:
|
|
|
from unittest.mock import patch
|
|
|
@@ -31,44 +32,36 @@ else:
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
-class TestBotServer(unittest.TestCase):
|
|
|
- def test_get_bot_id(self):
|
|
|
- with patch('desktop.lib.botserver.views.slack_client.api_call') as api_call:
|
|
|
- api_call.return_value = {
|
|
|
- 'members': [
|
|
|
- {
|
|
|
- 'name': 'hue_bot',
|
|
|
- 'deleted': False,
|
|
|
- 'id': 'U01K99VEDR9'
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- assert_equal(get_bot_id('hue_bot'), 'U01K99VEDR9')
|
|
|
-
|
|
|
- api_call.return_value = {
|
|
|
- 'members': [
|
|
|
- {
|
|
|
- 'name': 'hue_bot',
|
|
|
- 'deleted': True,
|
|
|
- 'id': 'U01K99VEDR9'
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- assert_equal(get_bot_id('hue_bot'), None)
|
|
|
-
|
|
|
- def test_say_hi_user(self):
|
|
|
- with patch('desktop.lib.botserver.views.slack_client.api_call') as api_call:
|
|
|
- api_call.return_value = {
|
|
|
- "ok": True
|
|
|
- }
|
|
|
- response = say_hi_user("channel", "user_id")
|
|
|
- assert_true(response['ok'])
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+if conf.SLACK.IS_ENABLED.get():
|
|
|
+ class TestBotServer(unittest.TestCase):
|
|
|
+ def test_get_bot_id(self):
|
|
|
+ with patch('desktop.lib.botserver.views.slack_client.api_call') as api_call:
|
|
|
+ api_call.return_value = {
|
|
|
+ 'members': [
|
|
|
+ {
|
|
|
+ 'name': 'hue_bot',
|
|
|
+ 'deleted': False,
|
|
|
+ 'id': 'U01K99VEDR9'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ assert_equal(get_bot_id('hue_bot'), 'U01K99VEDR9')
|
|
|
|
|
|
+ api_call.return_value = {
|
|
|
+ 'members': [
|
|
|
+ {
|
|
|
+ 'name': 'hue_bot',
|
|
|
+ 'deleted': True,
|
|
|
+ 'id': 'U01K99VEDR9'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ assert_equal(get_bot_id('hue_bot'), None)
|
|
|
|
|
|
+ def test_say_hi_user(self):
|
|
|
+ with patch('desktop.lib.botserver.views.slack_client.api_call') as api_call:
|
|
|
+ api_call.return_value = {
|
|
|
+ "ok": True
|
|
|
+ }
|
|
|
+ response = say_hi_user("channel", "user_id")
|
|
|
+ assert_true(response['ok'])
|