From 2e9a3e14190c45e5fe164ae34b38075cfbb17f00 Mon Sep 17 00:00:00 2001 From: Arash Date: Wed, 14 Apr 2021 16:17:20 -0400 Subject: [PATCH] added redshift and postgres --- superset/db_engine_specs/mysql.py | 3 +- superset/db_engine_specs/postgres.py | 10 +++++++ superset/db_engine_specs/redshift.py | 10 +++++++ superset/errors.py | 3 +- tests/db_engine_specs/mysql_tests.py | 21 +++++++++----- tests/db_engine_specs/postgres_tests.py | 35 ++++++++++++++++++++--- tests/db_engine_specs/redshift_tests.py | 38 +++++++++++++++++++++---- 7 files changed, 102 insertions(+), 18 deletions(-) diff --git a/superset/db_engine_specs/mysql.py b/superset/db_engine_specs/mysql.py index 962ad67d929bb..049ff16795951 100644 --- a/superset/db_engine_specs/mysql.py +++ b/superset/db_engine_specs/mysql.py @@ -124,7 +124,8 @@ class MySQLEngineSpec(BaseEngineSpec): ), TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: ( __( - 'We were unable to connect to your database named "%(database)s". Please verify your database name and try again.' + 'We were unable to connect to your database named "%(database)s". ' + "Please verify your database name and try again." ), SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, ), diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py index 59effff0cd7b8..9de12643798f4 100644 --- a/superset/db_engine_specs/postgres.py +++ b/superset/db_engine_specs/postgres.py @@ -76,6 +76,9 @@ class FixedOffsetTimezone(_FixedOffset): r'host "(?P.*?)" (\(.*?\) )?and accepting\s+TCP/IP ' r"connections on port (?P.*?)\?" ) +TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( + 'database "(?P.*?)" does not exist' +) class PostgresBaseEngineSpec(BaseEngineSpec): @@ -120,6 +123,13 @@ class PostgresBaseEngineSpec(BaseEngineSpec): ), SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR, ), + TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: ( + __( + 'We were unable to connect to your database named "%(database)s".' + " Please verify your database name and try again." + ), + SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, + ), } @classmethod diff --git a/superset/db_engine_specs/redshift.py b/superset/db_engine_specs/redshift.py index 90afc27dc05af..113cadf98d6be 100644 --- a/superset/db_engine_specs/redshift.py +++ b/superset/db_engine_specs/redshift.py @@ -39,6 +39,9 @@ r'host "(?P.*?)" (\(.*?\) )?and accepting\s+TCP/IP ' r"connections on port (?P.*?)\?" ) +TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( + 'database "(?P.*?)" does not exist' +) class RedshiftEngineSpec(PostgresBaseEngineSpec): @@ -66,6 +69,13 @@ class RedshiftEngineSpec(PostgresBaseEngineSpec): ), SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR, ), + TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: ( + __( + 'We were unable to connect to your database named "%(database)s".' + " Please verify your database name and try again." + ), + SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, + ), } @staticmethod diff --git a/superset/errors.py b/superset/errors.py index 4a9f2ae90a511..dc60083612daa 100644 --- a/superset/errors.py +++ b/superset/errors.py @@ -185,7 +185,8 @@ class SupersetErrorType(str, Enum): { "code": 1015, "message": _( - "Issue 1015 - Either the database is spelled incorrectly or does not exist." + "Issue 1015 - Either the database is " + "spelled incorrectly or does not exist." ), } ], diff --git a/tests/db_engine_specs/mysql_tests.py b/tests/db_engine_specs/mysql_tests.py index 5bd602ee1ee00..f619bdd066c78 100644 --- a/tests/db_engine_specs/mysql_tests.py +++ b/tests/db_engine_specs/mysql_tests.py @@ -122,7 +122,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1014, - "message": "Issue 1014 - Either the username or the password is wrong.", + "message": "Issue 1014 - Either the" + " username or the password is wrong.", } ], }, @@ -141,7 +142,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname" + " provided can't be resolved.", } ], }, @@ -153,14 +155,16 @@ def test_extract_errors(self): assert result == [ SupersetError( error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR, - message='The host "badconnection.com" might be down and can\'t be reached.', + message='The host "badconnection.com" might be ' + "down and can't be reached.", level=ErrorLevel.ERROR, extra={ "engine_name": "MySQL", "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided" + " can't be resolved.", } ], }, @@ -179,7 +183,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 10007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided " + "can't be resolved.", } ], }, @@ -191,14 +196,16 @@ def test_extract_errors(self): assert result == [ SupersetError( error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, - message='We were unable to connect to your database named "badDB". Please verify your database name and try again.', + message='We were unable to connect to your database named "badDB".' + " Please verify your database name and try again.", level=ErrorLevel.ERROR, extra={ "engine_name": "MySQL", "issue_codes": [ { "code": 10015, - "message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.", + "message": "Issue 1015 - Either the database is " + "spelled incorrectly or does not exist.", } ], }, diff --git a/tests/db_engine_specs/postgres_tests.py b/tests/db_engine_specs/postgres_tests.py index 867faa1265fb0..164c1211d6dc8 100644 --- a/tests/db_engine_specs/postgres_tests.py +++ b/tests/db_engine_specs/postgres_tests.py @@ -238,7 +238,10 @@ def test_extract_errors(self): ) ] - msg = 'psql: error: could not translate host name "locahost" to address: nodename nor servname provided, or not known' + msg = ( + 'psql: error: could not translate host name "locahost" to address: ' + "nodename nor servname provided, or not known" + ) result = PostgresEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -250,7 +253,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided " + "can't be resolved.", } ], }, @@ -303,7 +307,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1009, - "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", + "message": "Issue 1009 - The host might be down, " + "and can't be reached on the provided port.", } ], }, @@ -332,7 +337,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1009, - "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", + "message": "Issue 1009 - The host might be down, " + "and can't be reached on the provided port.", } ], }, @@ -360,3 +366,24 @@ def test_extract_errors(self): }, ) ] + + msg = 'database "badDB" does not exist' + result = PostgresEngineSpec.extract_errors(Exception(msg)) + assert result == [ + SupersetError( + error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, + message='We were unable to connect to your database named "badDB".' + " Please verify your database name and try again.", + level=ErrorLevel.ERROR, + extra={ + "engine_name": "PostgreSQL", + "issue_codes": [ + { + "code": 10015, + "message": "Issue 1015 - Either the database is " + "spelled incorrectly or does not exist.", + } + ], + }, + ) + ] diff --git a/tests/db_engine_specs/redshift_tests.py b/tests/db_engine_specs/redshift_tests.py index cacb90a8eaaa0..fa0353d1af16a 100644 --- a/tests/db_engine_specs/redshift_tests.py +++ b/tests/db_engine_specs/redshift_tests.py @@ -39,14 +39,18 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1014, - "message": "Issue 1014 - Either the username or the password is wrong", + "message": "Issue 1014 - Either the username or " + "the password is wrong", } ], }, ) ] - msg = 'redshift: error: could not translate host name "badhost" to address: nodename nor servname provided, or not known' + msg = ( + 'redshift: error: could not translate host name "badhost" ' + "to address: nodename nor servname provided, or not known" + ) result = RedshiftEngineSpec.extract_errors(Exception(msg)) assert result == [ SupersetError( @@ -58,7 +62,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided " + "can't be resolved.", } ], }, @@ -110,7 +115,8 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1009, - "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", + "message": "Issue 1009 - The host might be down, " + "and can't be reached on the provided port.", } ], }, @@ -139,7 +145,29 @@ def test_extract_errors(self): "issue_codes": [ { "code": 1009, - "message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", + "message": "Issue 1009 - The host might be down, " + "and can't be reached on the provided port.", + } + ], + }, + ) + ] + + msg = 'database "badDB" does not exist' + result = RedshiftEngineSpec.extract_errors(Exception(msg)) + assert result == [ + SupersetError( + error_type=SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR, + message='We were unable to connect to your database named "badDB".' + " Please verify your database name and try again.", + level=ErrorLevel.ERROR, + extra={ + "engine_name": "Amazon Redshift", + "issue_codes": [ + { + "code": 10015, + "message": "Issue 1015 - Either the database is " + "spelled incorrectly or does not exist.", } ], },