Explorar el Código

HUE-9205 [editor] Add query error propagation test in hive connector

Romain hace 5 años
padre
commit
1b1accbbe3

+ 39 - 4
desktop/libs/notebook/src/notebook/connectors/hiveserver2_tests.py

@@ -24,7 +24,7 @@ import sys
 import time
 
 from nose.plugins.skip import SkipTest
-from nose.tools import assert_equal, assert_true
+from nose.tools import assert_equal, assert_true, assert_raises
 
 from django.urls import reverse
 from TCLIService.ttypes import TStatusCode, TProtocolVersion, TOperationType
@@ -35,11 +35,13 @@ from desktop.lib.i18n import smart_str
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import add_to_group, grant_access
 from beeswax.server import dbms
+from beeswax.server.dbms import QueryServerException
 from beeswax.test_base import BeeswaxSampleProvider, get_query_server_config, is_hive_on_spark
 from hadoop.pseudo_hdfs4 import is_live_cluster
 from useradmin.models import User
 
 from notebook.api import _save_notebook
+from notebook.connectors.base import QueryError
 from notebook.connectors.hiveserver2 import HS2Api
 from notebook.models import make_notebook, Notebook
 
@@ -52,7 +54,7 @@ else:
 LOG = logging.getLogger(__name__)
 
 
-class TestApi(object):
+class TestApiWithConnectors(object):
 
   NOTEBOOK_JSON = """
     {
@@ -270,7 +272,7 @@ class TestApi(object):
     assert_equal(data['result']['handle']['statement'], 'SELECT * from customers')
 
 
-class TestHS2Api():
+class TestApi():
 
   def setUp(self):
     self.client = make_logged_in_client(username="test", groupname="default", recreate=True, is_superuser=False)
@@ -315,7 +317,40 @@ class TestHS2Api():
         assert_equal(jobs[0]['url'], '')  # Is empty
 
 
-class TestHiveserver2Api(object):
+  def test_get_error_message_from_query(self):
+    with patch('notebook.connectors.hiveserver2.HS2Api._get_db') as _get_db:
+      with patch('notebook.connectors.hiveserver2.HS2Api._get_current_statement') as _get_current_statement:
+        with patch('notebook.connectors.hiveserver2.HS2Api._get_session') as _get_session:
+          with patch('notebook.connectors.hiveserver2.HS2Api._prepare_hql_query') as _prepare_hql_query:
+            with patch('notebook.connectors.hiveserver2.HS2Api._get_session_by_id') as _get_session_by_id:
+              _get_db.return_value = Mock(
+                use=Mock(
+                ),
+                client=Mock(
+                  query=Mock(
+                    side_effect=QueryServerException(
+                      Exception('Execution error!'),
+                      message='Error while compiling statement: FAILED: HiveAccessControlException Permission denied'
+                    )
+                  ),
+                ),
+              )
+              notebook, snippet = {}, {'type': 'hive'}
+
+              api = HS2Api(self.user)
+
+              assert_raises(QueryError, api.execute, notebook, snippet)
+
+              try:
+                api = api.execute(notebook, snippet)
+              except QueryError as e:
+                assert_equal(
+                  e.message,
+                  'Error while compiling statement: FAILED: HiveAccessControlException Permission denied',
+                )
+
+
+class TestHiveserver2ApiNonMock(object):
 
   def setUp(self):
     self.client = make_logged_in_client(username="test", groupname="test", recreate=False, is_superuser=False)

+ 1 - 9
desktop/libs/notebook/src/notebook/urls.py

@@ -17,18 +17,10 @@
 
 from django.conf.urls import url
 
-# FIXME: This could be replaced with hooking into the `AppConfig.ready()`
-# signal in Django 1.7:
-#
-# https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready
-#
-# For now though we have to load in the monkey patches here because we know
-# this file has been loaded after `desktop.settings` has been loaded.
-
-# Start DBProxy server
 from notebook import views as notebook_views
 from notebook import api as notebook_api
 
+
 # Views
 urlpatterns = [
   url(r'^$', notebook_views.notebook, name='index'),