|
@@ -55,32 +55,21 @@ class TestBotServer(unittest.TestCase):
|
|
|
self.client_not_me = make_logged_in_client(username="test_not_me", groupname="default", recreate=True, is_superuser=False)
|
|
self.client_not_me = make_logged_in_client(username="test_not_me", groupname="default", recreate=True, is_superuser=False)
|
|
|
self.user_not_me = User.objects.get(username="test_not_me")
|
|
self.user_not_me = User.objects.get(username="test_not_me")
|
|
|
|
|
|
|
|
- def test_send_hi_user(self):
|
|
|
|
|
- with patch('desktop.lib.botserver.views.slack_client.api_call') as api_call:
|
|
|
|
|
- api_call.return_value = {
|
|
|
|
|
- "ok": True
|
|
|
|
|
- }
|
|
|
|
|
- send_hi_user("channel", "user_id")
|
|
|
|
|
- api_call.assert_called_with(api_method='chat.postMessage', json={'channel': 'channel', 'text': 'Hi <@user_id> :wave:'})
|
|
|
|
|
-
|
|
|
|
|
- api_call.side_effect = PopupException('message')
|
|
|
|
|
- assert_raises(PopupException, send_hi_user, "channel", "user_id")
|
|
|
|
|
-
|
|
|
|
|
def test_handle_on_message(self):
|
|
def test_handle_on_message(self):
|
|
|
- with patch('desktop.lib.botserver.views.send_hi_user') as say_hi_user:
|
|
|
|
|
|
|
+ with patch('desktop.lib.botserver.views._send_message') as _send_message:
|
|
|
|
|
|
|
|
response = handle_on_message("channel", "bot_id", "text", "user_id")
|
|
response = handle_on_message("channel", "bot_id", "text", "user_id")
|
|
|
assert_equal(response.status_code, 200)
|
|
assert_equal(response.status_code, 200)
|
|
|
- assert_false(say_hi_user.called)
|
|
|
|
|
|
|
+ assert_false(_send_message.called)
|
|
|
|
|
|
|
|
handle_on_message("channel", None, None, "user_id")
|
|
handle_on_message("channel", None, None, "user_id")
|
|
|
- assert_false(say_hi_user.called)
|
|
|
|
|
|
|
+ assert_false(_send_message.called)
|
|
|
|
|
|
|
|
handle_on_message("channel", None, "text", "user_id")
|
|
handle_on_message("channel", None, "text", "user_id")
|
|
|
- assert_false(say_hi_user.called)
|
|
|
|
|
|
|
+ assert_false(_send_message.called)
|
|
|
|
|
|
|
|
handle_on_message("channel", None, "hello hue test", "user_id")
|
|
handle_on_message("channel", None, "hello hue test", "user_id")
|
|
|
- assert_true(say_hi_user.called)
|
|
|
|
|
|
|
+ assert_true(_send_message.called)
|
|
|
|
|
|
|
|
def test_handle_query_history_link(self):
|
|
def test_handle_query_history_link(self):
|
|
|
with patch('desktop.lib.botserver.views.slack_client.chat_unfurl') as chat_unfurl:
|
|
with patch('desktop.lib.botserver.views.slack_client.chat_unfurl') as chat_unfurl:
|
|
@@ -108,6 +97,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
users_info.return_value = {
|
|
users_info.return_value = {
|
|
|
"ok": True,
|
|
"ok": True,
|
|
|
"user": {
|
|
"user": {
|
|
|
|
|
+ "is_bot": False,
|
|
|
"profile": {
|
|
"profile": {
|
|
|
"email": "test_not_me@example.com"
|
|
"email": "test_not_me@example.com"
|
|
|
}
|
|
}
|
|
@@ -193,6 +183,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
users_info.return_value = {
|
|
users_info.return_value = {
|
|
|
"ok": True,
|
|
"ok": True,
|
|
|
"user": {
|
|
"user": {
|
|
|
|
|
+ "is_bot": False,
|
|
|
"profile": {
|
|
"profile": {
|
|
|
"email": "test@example.com"
|
|
"email": "test@example.com"
|
|
|
}
|
|
}
|
|
@@ -228,6 +219,18 @@ class TestBotServer(unittest.TestCase):
|
|
|
chat_unfurl.assert_called_with(channel=channel_id, ts=message_ts, unfurls=gist_preview)
|
|
chat_unfurl.assert_called_with(channel=channel_id, ts=message_ts, unfurls=gist_preview)
|
|
|
assert_false(send_result_file.called)
|
|
assert_false(send_result_file.called)
|
|
|
|
|
|
|
|
|
|
+ # Gist link sent directly from Hue to Slack via bot
|
|
|
|
|
+ users_info.return_value = {
|
|
|
|
|
+ "ok": True,
|
|
|
|
|
+ "user": {
|
|
|
|
|
+ "is_bot": True,
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ handle_on_link_shared(channel_id, message_ts, links, user_id)
|
|
|
|
|
+
|
|
|
|
|
+ chat_unfurl.assert_called_with(channel=channel_id, ts=message_ts, unfurls=gist_preview)
|
|
|
|
|
+ assert_false(send_result_file.called)
|
|
|
|
|
+
|
|
|
# Gist document does not exist
|
|
# Gist document does not exist
|
|
|
gist_url = "https://demo.gethue.com/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427"
|
|
gist_url = "https://demo.gethue.com/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427"
|
|
|
assert_raises(PopupException, handle_on_link_shared, "channel", "12.1", [{"url": gist_url}], "<@user_id>")
|
|
assert_raises(PopupException, handle_on_link_shared, "channel", "12.1", [{"url": gist_url}], "<@user_id>")
|
|
@@ -248,6 +251,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
users_info.return_value = {
|
|
users_info.return_value = {
|
|
|
"ok": True,
|
|
"ok": True,
|
|
|
"user": {
|
|
"user": {
|
|
|
|
|
+ "is_bot": False,
|
|
|
"profile": {
|
|
"profile": {
|
|
|
"email": "test_user_not_exist@example.com"
|
|
"email": "test_user_not_exist@example.com"
|
|
|
}
|
|
}
|