Skip to content

Commit ba7fa5e

Browse files
committed
[slack] Update botserver UTs
- Update the host domain in test links - Add test for `select 1` message
1 parent 6337d1a commit ba7fa5e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Diff for: desktop/core/src/desktop/lib/botserver/views_tests.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ def test_handle_on_message(self):
7272
assert_false(_send_message.called)
7373

7474
handle_on_message("channel", None, "hello hue test", "user_id")
75-
assert_true(_send_message.called)
75+
_send_message.assert_called_with("channel", 'Hi <@user_id> :wave:')
76+
77+
with patch('desktop.lib.botserver.views.slack_client.chat_postEphemeral') as chat_postEphemeral:
78+
handle_on_message("channel", None, "test select 1 test", "user_id")
79+
chat_postEphemeral.assert_called_with(
80+
channel="channel",
81+
user="user_id",
82+
text='Hi <@user_id>\nInstead of copy/pasting SQL, now you can send Editor links which unfurls in a rich preview!')
7683

7784
def test_handle_query_history_link(self):
7885
with patch('desktop.lib.botserver.views.slack_client.chat_unfurl') as chat_unfurl:
@@ -94,7 +101,7 @@ def test_handle_query_history_link(self):
94101
'uuid': 'doc uuid'
95102
}
96103
doc = Document2.objects.create(data=json.dumps(doc_data), owner=self.user)
97-
links = [{"url": "https://demo.gethue.com/hue/editor?editor=" + str(doc.id)}]
104+
links = [{"url": "https://{host_domain}/hue/editor?editor=".format(host_domain=self.host_domain) + str(doc.id)}]
98105

99106
# Slack user is Hue user but without read access sends link
100107
users_info.return_value = {
@@ -156,11 +163,11 @@ def test_handle_query_history_link(self):
156163
assert_true(send_result_file.called)
157164

158165
# Document does not exist
159-
qhistory_url = "https://demo.gethue.com/hue/editor?editor=109644"
166+
qhistory_url = "https://{host_domain}/hue/editor?editor=109644".format(host_domain=self.host_domain)
160167
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": qhistory_url}], "<@user_id>")
161168

162169
# Cannot unfurl link with invalid query link
163-
inv_qhistory_url = "https://demo.gethue.com/hue/editor/?type=4"
170+
inv_qhistory_url = "https://{host_domain}/hue/editor/?type=4".format(host_domain=self.host_domain)
164171
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": inv_qhistory_url}], "<@user_id>")
165172

166173
def test_handle_gist_link(self):
@@ -180,7 +187,7 @@ def test_handle_gist_link(self):
180187
data=json.dumps(doc_data),
181188
extra='mysql'
182189
)
183-
links = [{"url": "https://demo.gethue.com/hue/gist?uuid=" + gist_doc.uuid}]
190+
links = [{"url": "https://{host_domain}/hue/gist?uuid=".format(host_domain=self.host_domain) + gist_doc.uuid}]
184191

185192
# Slack user who is Hue user sends link
186193
users_info.return_value = {
@@ -235,11 +242,11 @@ def test_handle_gist_link(self):
235242
assert_false(send_result_file.called)
236243

237244
# Gist document does not exist
238-
gist_url = "https://demo.gethue.com/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427"
245+
gist_url = "https://{host_domain}/hue/gist?uuid=6d1c407b-d999-4dfd-ad23-d3a46c19a427".format(host_domain=self.host_domain)
239246
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": gist_url}], "<@user_id>")
240247

241248
# Cannot unfurl with invalid gist link
242-
inv_gist_url = "https://demo.gethue.com/hue/gist?uuids/=invalid_link"
249+
inv_gist_url = "https://{host_domain}/hue/gist?uuids/=invalid_link".format(host_domain=self.host_domain)
243250
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", [{"url": inv_gist_url}], "<@user_id>")
244251

245252
def test_slack_user_not_hue_user(self):
@@ -249,7 +256,7 @@ def test_slack_user_not_hue_user(self):
249256

250257
# Can be checked similarly with query link too
251258
doc_data = {"statement_raw": "SELECT 98765"}
252-
links = [{"url": "https://demo.gethue.com/hue/gist?uuid=some_uuid"}]
259+
links = [{"url": "https://{host_domain}/hue/gist?uuid=some_uuid".format(host_domain=self.host_domain)}]
253260
_get_gist_document.return_value = Mock(data=json.dumps(doc_data), owner=self.user, extra='mysql')
254261

255262
# Same domain but diff email prefix
@@ -274,4 +281,4 @@ def test_slack_user_not_hue_user(self):
274281
}
275282
}
276283
}
277-
assert_raises(PopupException, handle_on_link_shared, self.host_domain,"channel", "12.1", links, "<@user_id>")
284+
assert_raises(PopupException, handle_on_link_shared, self.host_domain, "channel", "12.1", links, "<@user_id>")

0 commit comments

Comments
 (0)