fix(database): test connection error message for module not found (#9634)

This commit is contained in:
Daniel Vaz Gaspar 2020-04-27 09:24:41 +01:00 committed by GitHub
parent 516bdf6db1
commit f07ca7d836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -1376,7 +1376,7 @@ class Superset(BaseSupersetView):
except CertificateException as ex:
logger.info(ex.message)
return json_error_response(ex.message)
except NoSuchModuleError as ex:
except (NoSuchModuleError, ModuleNotFoundError) as ex:
logger.info("Invalid driver %s", ex)
driver_name = make_url(uri).drivername
return json_error_response(

View File

@ -439,6 +439,25 @@ class CoreTests(SupersetTestCase):
expected_body,
)
data = json.dumps(
{
"uri": "mssql+pymssql://url",
"name": "examples",
"impersonate_user": False,
}
)
response = self.client.post(
"/superset/testconn", data=data, content_type="application/json"
)
assert response.status_code == 400
assert response.headers["Content-Type"] == "application/json"
response_body = json.loads(response.data.decode("utf-8"))
expected_body = {"error": "Could not load database driver: mssql+pymssql"}
assert response_body == expected_body, "%s != %s" % (
response_body,
expected_body,
)
def test_testconn_unsafe_uri(self, username="admin"):
self.login(username=username)
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = True