예제 #1
0
 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"
예제 #2
0
    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)
예제 #3
0
    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))
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
    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"