|
|
@@ -72,7 +72,14 @@ class TestBotServer(unittest.TestCase):
|
|
|
assert_false(_send_message.called)
|
|
|
|
|
|
handle_on_message("channel", None, "hello hue test", "user_id")
|
|
|
- assert_true(_send_message.called)
|
|
|
+ _send_message.assert_called_with("channel", 'Hi <@user_id> :wave:')
|
|
|
+
|
|
|
+ with patch('desktop.lib.botserver.views.slack_client.chat_postEphemeral') as chat_postEphemeral:
|
|
|
+ handle_on_message("channel", None, "test select 1 test", "user_id")
|
|
|
+ chat_postEphemeral.assert_called_with(
|
|
|
+ channel="channel",
|
|
|
+ user="user_id",
|
|
|
+ text='Hi <@user_id>\nInstead of copy/pasting SQL, now you can send Editor links which unfurls in a rich preview!')
|
|
|
|
|
|
def test_handle_query_history_link(self):
|
|
|
with patch('desktop.lib.botserver.views.slack_client.chat_unfurl') as chat_unfurl:
|
|
|
@@ -94,7 +101,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
'uuid': 'doc uuid'
|
|
|
}
|
|
|
doc = Document2.objects.create(data=json.dumps(doc_data), owner=self.user)
|
|
|
- links = [{"url": "https://demo.gethue.com/hue/editor?editor=" + str(doc.id)}]
|
|
|
+ links = [{"url": "https://{host_domain}/hue/editor?editor=".format(host_domain=self.host_domain) + str(doc.id)}]
|
|
|
|
|
|
# Slack user is Hue user but without read access sends link
|
|
|
users_info.return_value = {
|
|
|
@@ -156,11 +163,11 @@ class TestBotServer(unittest.TestCase):
|
|
|
assert_true(send_result_file.called)
|
|
|
|
|
|
# Document does not exist
|
|
|
- qhistory_url = "https://demo.gethue.com/hue/editor?editor=109644"
|
|
|
+ qhistory_url = "https://{host_domain}/hue/editor?editor=109644".format(host_domain=self.host_domain)
|
|
|
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": qhistory_url}], "<@user_id>")
|
|
|
|
|
|
# Cannot unfurl link with invalid query link
|
|
|
- inv_qhistory_url = "https://demo.gethue.com/hue/editor/?type=4"
|
|
|
+ inv_qhistory_url = "https://{host_domain}/hue/editor/?type=4".format(host_domain=self.host_domain)
|
|
|
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": inv_qhistory_url}], "<@user_id>")
|
|
|
|
|
|
def test_handle_gist_link(self):
|
|
|
@@ -180,7 +187,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
data=json.dumps(doc_data),
|
|
|
extra='mysql'
|
|
|
)
|
|
|
- links = [{"url": "https://demo.gethue.com/hue/gist?uuid=" + gist_doc.uuid}]
|
|
|
+ links = [{"url": "https://{host_domain}/hue/gist?uuid=".format(host_domain=self.host_domain) + gist_doc.uuid}]
|
|
|
|
|
|
# Slack user who is Hue user sends link
|
|
|
users_info.return_value = {
|
|
|
@@ -235,11 +242,11 @@ class TestBotServer(unittest.TestCase):
|
|
|
assert_false(send_result_file.called)
|
|
|
|
|
|
# Gist document does not exist
|
|
|
- gist_url = "https://demo.gethue.com/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427"
|
|
|
+ gist_url = "https://{host_domain}/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427".format(host_domain=self.host_domain)
|
|
|
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": gist_url}], "<@user_id>")
|
|
|
|
|
|
# Cannot unfurl with invalid gist link
|
|
|
- inv_gist_url = "https://demo.gethue.com/hue/gist?uuids/=invalid_link"
|
|
|
+ inv_gist_url = "https://{host_domain}/hue/gist?uuids/=invalid_link".format(host_domain=self.host_domain)
|
|
|
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": inv_gist_url}], "<@user_id>")
|
|
|
|
|
|
def test_slack_user_not_hue_user(self):
|
|
|
@@ -249,7 +256,7 @@ class TestBotServer(unittest.TestCase):
|
|
|
|
|
|
# Can be checked similarly with query link too
|
|
|
doc_data = {"statement_raw": "SELECT 98765"}
|
|
|
- links = [{"url": "https://demo.gethue.com/hue/gist?uuid=some_uuid"}]
|
|
|
+ links = [{"url": "https://{host_domain}/hue/gist?uuid=some_uuid".format(host_domain=self.host_domain)}]
|
|
|
_get_gist_document.return_value = Mock(data=json.dumps(doc_data), owner=self.user, extra='mysql')
|
|
|
|
|
|
# Same domain but diff email prefix
|
|
|
@@ -274,4 +281,4 @@ class TestBotServer(unittest.TestCase):
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- assert_raises(PopupException, handle_on_link_shared, self.host_domain,"channel", "12.1", links, "<@user_id>")
|
|
|
+ assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", links, "<@user_id>")
|