def test_extract_error_message_orig(self): DatabaseError = namedtuple("DatabaseError", ["error_dict"]) db_err = DatabaseError( {"errorName": "name", "errorLocation": "location", "message": "msg"} ) exception = Exception() exception.orig = db_err result = PrestoEngineSpec._extract_error_message(exception) assert result == "name at location: msg"
def test_validator_db_error(self, flask_g): flask_g.user.username = "******" sql = "SELECT 1 FROM default.notarealtable" schema = "default" fetch_fn = self.database.db_engine_spec.fetch_data fetch_fn.side_effect = DatabaseError("dummy db error") with self.assertRaises(PrestoSQLValidationError): self.validator.validate(sql, schema, self.database)
def test_validator_query_error(self, flask_g): flask_g.user.username = "******" sql = "SELECT 1 FROM default.notarealtable" schema = "default" fetch_fn = self.database.db_engine_spec.fetch_data fetch_fn.side_effect = DatabaseError(self.PRESTO_ERROR_TEMPLATE) errors = self.validator.validate(sql, schema, self.database) self.assertEqual(1, len(errors))
def test_get_create_view_database_error(self): from pyhive.exc import DatabaseError mock_execute = mock.MagicMock(side_effect=DatabaseError()) database = mock.MagicMock() database.get_sqla_engine.return_value.raw_connection.return_value.cursor.return_value.execute = ( mock_execute ) schema = "schema" table = "table" result = PrestoEngineSpec.get_create_view(database, schema=schema, table=table) assert result is None
def test_table_doesnot_exist(self): # arrange e = DatabaseError() setattr( e, 'message', {u'message': u'line 1:15: Table hive.schm1.tbl1 does not exist'}) client = mock.MagicMock(spec=PrestoClient) client.execute.side_effect = e catalog = 'hive' database = 'schm1' table = 'tbl1' # act target = PrestoTarget(client, catalog, database, table) exists = target.exists() # assert client.execute.assert_called_once_with( 'SELECT COUNT(*) AS cnt FROM hive.schm1.tbl1 WHERE 1 = %s LIMIT 1', [1], mode='fetch') assert not exists
def test_extract_error_message_db_errr(self): from pyhive.exc import DatabaseError exception = DatabaseError({"message": "Err message"}) result = PrestoEngineSpec._extract_error_message(exception) assert result == "Err message"