Selaa lähdekoodia

[metadata] Private UI Risk API is missing some connector properties

Updated test for private API.
Romain Rigaux 4 vuotta sitten
vanhempi
commit
313cfa134a

+ 6 - 2
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -199,13 +199,17 @@ def query_risk(request):
   interface = request.POST.get('interface', OPTIMIZER.INTERFACE.get())
   connector = json.loads(request.POST.get('connector', '{}'))
   if request.POST.get('query'):
+    # Via API
     query = json.loads(request.POST.get('query'))
+    source_platform = request.POST.get('sourcePlatform')
+    db_name = request.POST.get('dbName')
   else:
+    # Via Editor
     snippet = json.loads(request.POST.get('snippet'))
     should_close, resp = get_current_statement(snippet)
     query = resp['statement']
-  source_platform = request.POST.get('sourcePlatform')
-  db_name = request.POST.get('dbName')
+    source_platform = snippet['connector']['dialect']
+    db_name = snippet['database']
 
   api = get_api(request.user, interface)
 

+ 20 - 10
desktop/libs/metadata/src/metadata/optimizer_api_tests.py

@@ -24,6 +24,7 @@ from django.urls import reverse
 from nose.tools import assert_equal, assert_true, assert_false
 
 from desktop.auth.backend import rewrite_user
+from desktop.conf import ENABLE_ORGANIZATIONS
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import add_to_group, grant_access
 from useradmin.models import User
@@ -31,9 +32,9 @@ from useradmin.models import User
 from metadata.optimizer_api import _convert_queries
 
 if sys.version_info[0] > 2:
-  from unittest.mock import patch, Mock, MagicMock
+  from unittest.mock import patch, Mock
 else:
-  from mock import patch, Mock, MagicMock
+  from mock import patch, Mock
 
 
 LOG = logging.getLogger(__name__)
@@ -47,13 +48,16 @@ class TestApi():
     self.user = User.objects.get(username="test")
 
     self.user = rewrite_user(self.user)
-    add_to_group('test')
-    grant_access("test", "test", "metadata")
+    if not ENABLE_ORGANIZATIONS.get():
+      add_to_group('test')
+      grant_access("test", "test", "metadata")
 
 
-  def test_risk(self):
+  def test_risk_ui_api(self):
     snippet = {
-      "id": "2b7d1f46-17a0-30af-efeb-33d4c29b1055", "type": "hive", "status": "running",
+      "id": "2b7d1f46-17a0-30af-efeb-33d4c29b1055",
+      "type": "hive",
+      "status": "running",
       "statement": "select * from web_logs", "properties": {
         "settings": [], "variables": [], "files": [], "functions": []
       },
@@ -70,7 +74,16 @@ class TestApi():
           "guid": "7xm6+epkRx6dyvYvGNYePA==an"
         }
       },
-      "lastExecuted": 1462554843817, "database": "default"
+      "lastExecuted": 1462554843817,
+      "database": "default",
+      "connector": {
+        "name": "Hive",
+        "type": "6", "id": "6", "displayName": "Hive",
+        "optimizer": "api",
+        "is_sql": True,
+        "is_batchable": True,
+        "dialect": "hive"
+      }
     }
 
     with patch('metadata.optimizer_api.get_api') as get_api:
@@ -78,10 +91,7 @@ class TestApi():
 
       response = self.client.post(reverse('metadata:query_risk'), {
           'snippet': json.dumps(snippet),
-          'dbName': 'gethue',
-          'sourcePlatform': 'hive',
           'interface': 'dummy',
-          'connector': json.dumps('{}')
       })
 
       data = json.loads(response.content)