refactor: dbapi exception mapping for dbapi's (#12869)

* refactor: dbapi exception mapping for dbapi's

* fix test

* fix lint

* fix grammar on comment
This commit is contained in:
Daniel Vaz Gaspar
2021-02-02 15:07:46 +00:00
committed by GitHub
parent 275e57f4f1
commit 6c018c0a28
5 changed files with 129 additions and 6 deletions

View File

@@ -14,7 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from unittest import mock
import pytest
from superset.db_engine_specs.clickhouse import ClickHouseEngineSpec
from superset.db_engine_specs.exceptions import SupersetDBAPIDatabaseError
from tests.db_engine_specs.base_tests import TestDbEngineSpec
@@ -30,3 +35,13 @@ class TestClickHouseDbEngineSpec(TestDbEngineSpec):
ClickHouseEngineSpec.convert_dttm("DATETIME", dttm),
"toDateTime('2019-01-02 03:04:05')",
)
def test_execute_connection_error(self):
from urllib3.exceptions import NewConnectionError
cursor = mock.Mock()
cursor.execute.side_effect = NewConnectionError(
"Dummypool", message="Exception with sensitive data"
)
with pytest.raises(SupersetDBAPIDatabaseError) as ex:
ClickHouseEngineSpec.execute(cursor, "SELECT col1 from table1")