Skip to content

Commit

Permalink
[slack] Update botserver UTs
Browse files Browse the repository at this point in the history
- Update the host domain in test links
- Add test for `select 1` message
  • Loading branch information
Harshg999 committed May 12, 2021
1 parent 6337d1a commit ba7fa5e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions desktop/core/src/desktop/lib/botserver/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ def test_handle_on_message(self):
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:
Expand All @@ -94,7 +101,7 @@ def test_handle_query_history_link(self):
'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 = {
Expand Down Expand Up @@ -156,11 +163,11 @@ def test_handle_query_history_link(self):
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):
Expand All @@ -180,7 +187,7 @@ def test_handle_gist_link(self):
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 = {
Expand Down Expand Up @@ -235,11 +242,11 @@ def test_handle_gist_link(self):
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):
Expand All @@ -249,7 +256,7 @@ def test_slack_user_not_hue_user(self):

# 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
Expand All @@ -274,4 +281,4 @@ def test_slack_user_not_hue_user(self):
}
}
}
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>")

0 comments on commit ba7fa5e

Please sign in to comment.