@@ -72,7 +72,14 @@ def test_handle_on_message(self):
72
72
assert_false (_send_message .called )
73
73
74
74
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>\n Instead of copy/pasting SQL, now you can send Editor links which unfurls in a rich preview!' )
76
83
77
84
def test_handle_query_history_link (self ):
78
85
with patch ('desktop.lib.botserver.views.slack_client.chat_unfurl' ) as chat_unfurl :
@@ -94,7 +101,7 @@ def test_handle_query_history_link(self):
94
101
'uuid' : 'doc uuid'
95
102
}
96
103
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 )}]
98
105
99
106
# Slack user is Hue user but without read access sends link
100
107
users_info .return_value = {
@@ -156,11 +163,11 @@ def test_handle_query_history_link(self):
156
163
assert_true (send_result_file .called )
157
164
158
165
# 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 )
160
167
assert_raises (PopupException , handle_on_link_shared , self .host_domain , "channel" , "12.1" , [{"url" : qhistory_url }], "<@user_id>" )
161
168
162
169
# 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 )
164
171
assert_raises (PopupException , handle_on_link_shared , self .host_domain , "channel" , "12.1" , [{"url" : inv_qhistory_url }], "<@user_id>" )
165
172
166
173
def test_handle_gist_link (self ):
@@ -180,7 +187,7 @@ def test_handle_gist_link(self):
180
187
data = json .dumps (doc_data ),
181
188
extra = 'mysql'
182
189
)
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 }]
184
191
185
192
# Slack user who is Hue user sends link
186
193
users_info .return_value = {
@@ -235,11 +242,11 @@ def test_handle_gist_link(self):
235
242
assert_false (send_result_file .called )
236
243
237
244
# 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 )
239
246
assert_raises (PopupException , handle_on_link_shared , self .host_domain , "channel" , "12.1" , [{"url" : gist_url }], "<@user_id>" )
240
247
241
248
# 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 )
243
250
assert_raises (PopupException , handle_on_link_shared , self .host_domain , "channel" , "12.1" , [{"url" : inv_gist_url }], "<@user_id>" )
244
251
245
252
def test_slack_user_not_hue_user (self ):
@@ -249,7 +256,7 @@ def test_slack_user_not_hue_user(self):
249
256
250
257
# Can be checked similarly with query link too
251
258
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 ) }]
253
260
_get_gist_document .return_value = Mock (data = json .dumps (doc_data ), owner = self .user , extra = 'mysql' )
254
261
255
262
# Same domain but diff email prefix
@@ -274,4 +281,4 @@ def test_slack_user_not_hue_user(self):
274
281
}
275
282
}
276
283
}
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