浏览代码

[metastore] Fix a bunch of tests after the ajax-ification of metastore

Romain Rigaux 10 年之前
父节点
当前提交
44784583f0

+ 12 - 10
apps/beeswax/src/beeswax/tests.py

@@ -1156,18 +1156,20 @@ for x in sys.stdin:
     self.client.post('/beeswax/install_examples')
 
     # New tables exists
-    resp = self.client.get('/metastore/tables/')
-    assert_true('sample_08' in resp.content)
-    assert_true('sample_07' in resp.content)
-    assert_true('customers' in resp.content)
+    resp = self.client.get('/metastore/tables/?format=json')
+    data = json.loads(resp.content)
+    assert_true('sample_08' in data['table_names'])
+    assert_true('sample_07' in data['table_names'])
+    assert_true('customers' in data['table_names'])
 
     # Sample tables contain data (examples are installed in default DB)
-    resp = self.client.get('/metastore/table/default/sample_07')
-    assert_true('<table id="sampleTable' in resp.content, resp.content)
-    resp = self.client.get('/metastore/table/default/sample_08')
-    assert_true('<table id="sampleTable' in resp.content, resp.content)
-    resp = self.client.get('/metastore/table/default/customers')
-    assert_true('<table id="sampleTable' in resp.content, resp.content)
+    resp = self.client.get(reverse('beeswax:get_sample_data', kwargs={'database': 'default', 'table': 'sample_07'}))
+    data = json.loads(resp.content)
+    assert_true(data['rows'], data)
+    resp = self.client.get(reverse('beeswax:get_sample_data', kwargs={'database': 'default', 'table': 'sample_08'}))
+    data = json.loads(resp.content)
+    assert_true(data['rows'], data)
+    resp = self.client.get(reverse('beeswax:get_sample_data', kwargs={'database': 'default', 'table': 'customers'}))
 
     # New designs exists
     resp = self.client.get('/beeswax/list_designs')

+ 7 - 7
apps/metastore/src/metastore/templates/metastore.mako

@@ -486,7 +486,7 @@ ${ assist.assistPanel() }
         <!-- ko template: "metastore-columns-table" --><!-- /ko -->
         <!-- /ko -->
 
-        <a class="pointer" data-bind="visible: columns().length > 3, click: function() { $('li a[href=\'#columns\']').click(); }">
+        <a class="pointer" data-bind="visible: columns().length >= 3, click: function() { $('li a[href=\'#columns\']').click(); }">
           ${_('View more...')}
         </a>
       </div>
@@ -497,7 +497,7 @@ ${ assist.assistPanel() }
         <!-- ko if: loaded -->
         <!-- ko with: preview -->
         <!-- ko template: { if: rows().length, name: 'metastore-samples-table' } --><!-- /ko -->
-        <a class="pointer" data-bind="visible: rows().length > 3, click: function() { $('li a[href=\'#sample\']').click(); }"  style="display: none;">
+        <a class="pointer" data-bind="visible: rows().length >= 3, click: function() { $('li a[href=\'#sample\']').click(); }"  style="display: none;">
           ${_('View more...')}
         </a>
         <!-- /ko -->
@@ -513,9 +513,9 @@ ${ assist.assistPanel() }
         <!-- ko if: loaded -->
         <!-- ko with: preview -->
         <!-- ko template: { if: values().length, name: 'metastore-partition-values-table' } --><!-- /ko -->
-        <a class="pointer" data-bind="visible: values().length > 3, click: function() { $('li a[href=\'#partitions\']').click(); }"  style="display: none;">
+        <a class="pointer" data-bind="visible: values().length >= 3, click: function() { $('li a[href=\'#partitions\']').click(); }"  style="display: none;">
           ${_('View more...')}
-      </a>
+        </a>
         <!-- /ko -->
         <span data-bind="visible: !values().length" style="display: none;">${ _('The partition does not contain any values') }</span>
         <!-- /ko -->
@@ -543,9 +543,9 @@ ${ assist.assistPanel() }
         <!-- /ko -->
       </div>
       <!-- /ko -->
-##       <a href="${ url('metastore:describe_partitions', database=database, table=table.name) }">
-##         ${ _('View all') }
-##       </a>
+       ##<a href="${ url('metastore:describe_partitions', database=database, table=table.name) }">
+       ##  ${ _('View all') }
+       ##</a>
     </div>
 
     <div class="tab-pane" id="sample">

+ 20 - 22
apps/metastore/src/metastore/tests.py

@@ -79,18 +79,20 @@ class TestMetastoreWithHadoop(BeeswaxSampleProvider):
     assert_equal(200, response.status_code)
 
     # Switch databases
-    response = self.client.get("/metastore/tables/%s" % self.db_name)
-    assert_true('name' in response.context["tables"][0])
-    assert_true("test" in response.context["table_names"])
+    response = self.client.get("/metastore/tables/%s>format=json" % self.db_name)
+    data = json.loads(response.content)
+    assert_true('name' in data["tables"][0])
+    assert_true("test" in data["table_names"])
 
     # Should default to "default" database
     response = self.client.get("/metastore/tables/not_there")
     assert_equal(200, response.status_code)
 
     # And have detail
-    response = self.client.get("/metastore/table/%s/test" % self.db_name)
-    assert_true("foo" in response.content)
-    assert_true("SerDe Library" in response.content, response.content)
+    response = self.client.get("/metastore/table/%s/test?format=json" % self.db_name)
+    data = json.loads(response.content)
+    assert_true("foo" in [col['name'] for col in data['cols']])
+    assert_true("SerDe Library" in data['properties'], data)
 
     # Remember the number of history items. Use a generic fragment 'test' to pass verification.
     history_cnt = verify_history(self.client, fragment='test')
@@ -151,27 +153,23 @@ class TestMetastoreWithHadoop(BeeswaxSampleProvider):
     assert_false('test_index' in data['tables'])
 
   def test_describe_view(self):
-    resp = self.client.get('/metastore/table/%s/myview' % self.db_name)
-    assert_true(resp.context['table'].is_view)
-    assert_true("View" in resp.content)
-    assert_true("Drop View" in resp.content)
-    # Breadcrumbs
-    assert_true(self.db_name in resp.content)
-    assert_true("myview" in resp.content)
+    resp = self.client.get('/metastore/table/%s/myview?format=json' % self.db_name)
+    assert_equal(200, response.status_code, response.content)
+    data = json.loads(response.content)
+    assert_true(data['is_view'])
+    assert_equal("myview", data['name'])
 
   def test_describe_partitions(self):
     response = self.client.get("/metastore/table/%s/test_partitions" % self.db_name)
     assert_true("Show Partitions (2)" in response.content, response.content)
 
-    response = self.client.get("/metastore/table/%s/test_partitions/partitions" % self.db_name, follow=True)
-    assert_true("baz_one" in response.content)
-    assert_true("boom_two" in response.content)
-    assert_true("baz_foo" in response.content)
-    assert_true("boom_bar" in response.content)
-    # Breadcrumbs
-    assert_true(self.db_name in response.content)
-    assert_true("test_partitions" in response.content)
-    assert_true("partitions" in response.content)
+    response = self.client.get("/metastore/table/%s/test_partitions/partitions?format=json" % self.db_name, follow=True)
+    data = json.loads(response.content)
+    partition_columns = [col for cols in data['massaged_partitions'] for col in cols['columns']]
+    assert_true("baz_one" in partition_columns)
+    assert_true("boom_two" in partition_columns)
+    assert_true("baz_foo" in partition_columns)
+    assert_true("boom_bar" in partition_columns)
 
     # Not partitioned
     response = self.client.get("/metastore/table/%s/test/partitions" % self.db_name, follow=True)

+ 1 - 0
apps/metastore/src/metastore/views.py

@@ -75,6 +75,7 @@ def databases(request):
   return render("metastore.mako", request, {
     'breadcrumbs': [],
     'database': None,
+    'databases': databases,
     'partitions': [],
     'has_write_access': has_write_access(request.user),
   })

+ 4 - 4
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -24,7 +24,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.i18n import force_unicode
 
 from notebook.connectors.base import Api, QueryError, QueryExpired
-from beeswax.design import strip_trailing_semicolon, split_statements
+
 
 LOG = logging.getLogger(__name__)
 
@@ -32,7 +32,7 @@ LOG = logging.getLogger(__name__)
 try:
   from beeswax import data_export
   from beeswax.api import _autocomplete
-  from beeswax.design import hql_query
+  from beeswax.design import hql_query, strip_trailing_semicolon, split_statements
   from beeswax import conf as beeswax_conf
   from beeswax.models import QUERY_TYPES, HiveServerQueryHandle, QueryHistory, HiveServerQueryHistory
   from beeswax.server import dbms
@@ -60,7 +60,7 @@ class HS2Api(Api):
   def _get_handle(self, snippet):
     snippet['result']['handle']['secret'], snippet['result']['handle']['guid'] = HiveServerQueryHandle.get_decoded(snippet['result']['handle']['secret'], snippet['result']['handle']['guid'])
     snippet['result']['handle'].pop('statement_id')
-    snippet['result']['handle'].pop('has_more') 
+    snippet['result']['handle'].pop('has_more')
     return HiveServerQueryHandle(**snippet['result']['handle'])
 
   def _get_db(self, snippet):
@@ -108,7 +108,7 @@ class HS2Api(Api):
 
   def _get_statements(self, hql_query):
     hql_query = strip_trailing_semicolon(hql_query)
-    return [strip_trailing_semicolon(statement.strip()) for statement in split_statements(hql_query)]    
+    return [strip_trailing_semicolon(statement.strip()) for statement in split_statements(hql_query)]
 
   @query_error_handler
   def check_status(self, notebook, snippet):

+ 2 - 2
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -927,9 +927,9 @@
       $.each(notebook.snippets, function (index, snippet) {
         self.addSnippet(snippet);
       });
-      if (vm.editorMode && ! notebook.snippets.length) {
+      if (vm.editorMode && notebook.snippets.length == 0) {
         self.showHistory(true); // Show history when new query
-      }      
+      }
     }
 
     self.save = function () {

+ 4 - 4
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -864,8 +864,8 @@ ${ require.config() }
       <i class="fa fa-fw fa-stop"></i>
     </a>
     <a class="snippet-side-btn" data-bind="click: reexecute, visible: $root.editorMode && result && result.handle().has_more, css: {'blue': $parent.history().length == 0 || $root.editorMode, 'disabled': statement() === '' }" title="${ _('CTRL + ENTER') }">
-      <i class="fa fa-fw fa-cog"></i>
-    </a>    
+      <i class="fa fa-fw fa-sign-out"></i>
+    </a>
     <a class="snippet-side-btn" data-bind="click: execute, visible: status() != 'running' && status() != 'loading', css: {'blue': $parent.history().length == 0 || $root.editorMode, 'disabled': statement() === '' }" title="${ _('CTRL + ENTER') }">
       <i class="fa fa-fw fa-play"></i>
     </a>
@@ -873,7 +873,7 @@ ${ require.config() }
       <a class="snippet-side-btn" data-bind="click: function() { $parent.showHistory(! $parent.showHistory()); window.setTimeout(redrawFixedHeaders, 100); }, css: {'blue': true}" title="${ _('Re-execute from the first statement') }">
         <i class="fa fa-fw fa-history"></i>
       </a>
-    <!-- /ko -->    
+    <!-- /ko -->
   </div>
 </script>
 
@@ -1065,7 +1065,7 @@ ${ require.config() }
   </div>
   <div class="modal-footer">
     <a class="btn" data-dismiss="modal">${_('Cancel')}</a>
-    <a class="btn btn-primary disable-feedback" data-dismiss="modal" data-bind="click: saveAsNotebook">${_('Save')}</a> 
+    <a class="btn btn-primary disable-feedback" data-dismiss="modal" data-bind="click: saveAsNotebook">${_('Save')}</a>
   </div>
 </div>