superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch 0.20 updated: views: don't explode on test connection (#3828)
Date Sun, 12 Nov 2017 05:45:56 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch 0.20
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/0.20 by this push:
     new 0ed66c9  views: don't explode on test connection (#3828)
0ed66c9 is described below

commit 0ed66c9e02a8150b9f866332b4f43f6b058ca289
Author: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
AuthorDate: Sun Nov 12 06:45:54 2017 +0100

    views: don't explode on test connection (#3828)
    
    If we don't have the database saved.
    
    Props to LittleQ (sqj597) for the fix.
    
    Fix #3799
---
 superset/views/core.py |  4 ++--
 tests/core_tests.py    | 21 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/superset/views/core.py b/superset/views/core.py
index bd4d4e5..d79a3f2 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1444,12 +1444,12 @@ class Superset(BaseSupersetView):
                     # the password-masked uri was passed
                     # use the URI associated with this database
                     uri = database.sqlalchemy_uri_decrypted
-            
+
             url = make_url(uri)
             db_engine = models.Database.get_db_engine_spec_for_backend(url.get_backend_name())
             db_engine.patch()
             uri = db_engine.get_uri_for_impersonation(uri, impersonate_user, username)
-            masked_url = database.get_password_masked_url_from_uri(uri)
+            masked_url = models.Database.get_password_masked_url_from_uri(uri)
 
             logging.info("Superset.testconn(). Masked URL: {0}".format(masked_url))
 
diff --git a/tests/core_tests.py b/tests/core_tests.py
index c533553..d339504 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -6,9 +6,10 @@ from __future__ import unicode_literals
 
 import csv
 import doctest
+import io
 import json
 import logging
-import io
+import mock
 import random
 import unittest
 
@@ -300,6 +301,24 @@ class CoreTests(SupersetTestCase):
         assert response.status_code == 200
         assert response.headers['Content-Type'] == 'application/json'
 
+    def test_testconn_does_work_without_a_database(self, username='admin'):
+        self.login(username=username)
+        database = self.get_main_database(db.session)
+
+        data = json.dumps({
+            'uri': database.safe_sqlalchemy_uri(),
+            'name': '',
+            'impersonate_user': False
+        })
+        engine = mock.Mock()
+        engine.connect = mock.Mock()
+        engine.table_names = mock.Mock(return_value=[])
+        with mock.patch('superset.views.core.create_engine', return_value=engine):
+            response = self.client.post('/superset/testconn', data=data, content_type='application/json')
+        engine.table_names.assert_called_with()
+        assert response.status_code == 200
+        assert response.headers['Content-Type'] == 'application/json'
+
     def test_custom_password_store(self):
         database = self.get_main_database(db.session)
         conn_pre = sqla.engine.url.make_url(database.sqlalchemy_uri_decrypted)

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message