[slack] Delete doc in UT and fix pylint issues
@@ -77,7 +77,7 @@ class TestBotServer(unittest.TestCase):
client = make_logged_in_client(username="test", groupname="default", recreate=True, is_superuser=False)
user = User.objects.get(username="test")
channel_id = "channel_id"
- message_ts = "12345.123"
+ message_ts = "123.1"
# qhistory link
links = [{"url": "https://demo.gethue.com/hue/editor?editor=123456"}]
@@ -88,20 +88,26 @@ class TestBotServer(unittest.TestCase):
"statement_raw": "SELECT 5000",
}]
}
-
- Document2.objects.create(id=123456, data=json.dumps(doc_data), owner=user)
+ doc = Document2.objects.create(id=123456, data=json.dumps(doc_data), owner=user)
+ try:
handle_on_link_shared(channel_id, message_ts, links)
+ finally:
+ doc.delete()
mock_unfurl_payload.assert_called_with(links[0]["url"], "SELECT 5000", "Mysql", "test")
assert_true(chat_unfurl.called)
# gist link
doc_data = {"statement_raw": "SELECT 98765"}
+ links = []
+ try:
gist_doc = Document2.objects.create(id=101010, data=json.dumps(doc_data), owner=user, extra='mysql', type='gist')
links = [{"url": "http://demo.gethue.com/hue/gist?uuid="+str(gist_doc.uuid)}]
handle_on_link_shared(channel_id, message_ts, links)
+ finally:
+ gist_doc.delete()
mock_unfurl_payload.assert_called_with(links[0]["url"], "SELECT 98765", "Mysql", "test")
assert_true(chat_unfurl.called)
# Cannot unfurl link
- assert_raises(PopupException, handle_on_link_shared, "channel_id", "12345.123", [{"url": "https://demo.gethue.com/hue/editor/?type=4"}])
- assert_raises(PopupException, handle_on_link_shared, "channel_id", "12345.123", [{"url": "http://demo.gethue.com/hue/gist?uuids/=something"}])
+ assert_raises(PopupException, handle_on_link_shared, "channel_id", "123.1", [{"url": "https://demo.gethue.com/hue/editor/?type=4"}])
+ assert_raises(PopupException, handle_on_link_shared, "channel_id", "123.1", [{"url": "http://demo.gethue.com/hue/gist?uuids/=xyz"}])
