Răsfoiți Sursa

HUE-1817 [beeswax] Migrate several tests to the new API

Move UTF decode to Queries page only
Romain Rigaux 12 ani în urmă
părinte
comite
2498d03c7f

+ 9 - 7
apps/beeswax/src/beeswax/templates/list_designs.mako

@@ -16,8 +16,10 @@
 <%!
     import time
     from django.template.defaultfilters import timesince
-    from desktop.views import commonheader, commonfooter
+    from django.utils.encoding import force_unicode    
     from django.utils.translation import ugettext as _
+
+    from desktop.views import commonheader, commonfooter
 %>
 
 <%namespace name="actionbar" file="actionbar.mako" />
@@ -26,7 +28,7 @@
 
 ${ commonheader(_('Saved Queries'), app_name, user) | n,unicode }
 
-${layout.menubar(section='saved queries')}
+${ layout.menubar(section='saved queries') }
 
 <div class="container-fluid">
   <div class="card card-small">
@@ -101,25 +103,25 @@ ${layout.menubar(section='saved queries')}
         </td>
         <td>
         % if may_edit:
-          <a href="${ url(app_name + ':execute_query', design_id=design.id) }" data-row-selector="true">${design.name}</a>
+          <a href="${ url(app_name + ':execute_query', design_id=design.id) }" data-row-selector="true">${ force_unicode(design.name) }</a>
         % else:
-          ${ design.name }
+          ${ force_unicode(design.name) }
         % endif
         </td>
         <td>
         % if design.desc:
-          ${ design.desc }
+          ${ force_unicode(design.desc) }
         % endif
         </td>
         <td>${ design.owner.username }</td>
-        <td data-sort-value="${time.mktime(design.mtime.timetuple())}">${ timesince(design.mtime) } ${_('ago')}</td>
+        <td data-sort-value="${time.mktime(design.mtime.timetuple())}">${ timesince(design.mtime) } ${ _('ago') }</td>
       </tr>
       % endfor
     </tbody>
   </table>
     <div class="card-body">
       <p>
-        ${comps.pagination(page)}
+        ${ comps.pagination(page) }
       </p>
     </div>
   </div>

+ 2 - 0
apps/beeswax/src/beeswax/test_base.py

@@ -273,6 +273,8 @@ def make_query(client, query, submission_type="Execute",
 
   if submission_type == 'Explain':
     execute_url += "?explain=true"
+  if submission_type == 'Save':
+    execute_url = reverse("beeswax:api_save_query")
 
   response = client.post(execute_url, parameters, **kwargs)
 

+ 9 - 7
apps/beeswax/src/beeswax/tests.py

@@ -742,10 +742,10 @@ for x in sys.stdin:
 
 
   def test_save_results_to_dir(self):
-    """Check that saving to directory works"""
 
     def save_and_verify(select_resp, target_dir, verify=True):
-      qid = select_resp.context['query'].id
+      content = json.loads(select_resp.content)
+      qid = content['id']
       save_data = {
         'type': 'hdfs',
         'path': target_dir
@@ -799,11 +799,11 @@ for x in sys.stdin:
 
 
   def test_save_results_to_tbl(self):
-    """Check that saving to new table works"""
 
     def save_and_verify(select_resp, target_tbl):
       """Check that saving to table works"""
-      qid = select_resp.context['query'].id
+      content = json.loads(select_resp.content)
+      qid = content['id']
       save_data = {
         'type': 'hive-table',
         'path': target_tbl
@@ -1586,10 +1586,12 @@ class TestWithMockedServer(object):
 
   def test_bulk_query_trash(self):
     response = _make_query(self.client, 'SELECT', submission_type='Save', name='My Name 1', desc='My Description')
-    query = response.context['design']
+    content = json.loads(response.content)
+    query = content['design_id']
     response = _make_query(self.client, 'SELECT', submission_type='Save', name='My Name 2', desc='My Description')
-    query2 = response.context['design']
-    ids = [query.id, query2.id]
+    content = json.loads(response.content)
+    query2 = content['design_id']
+    ids = [query, query2]
 
     resp = self.client.get('/beeswax/list_designs')
     ids_page_1 = set([query.id for query in resp.context['page'].object_list])

+ 1 - 2
apps/metastore/src/metastore/tests.py

@@ -98,8 +98,7 @@ class TestMetastoreWithHadoop(BeeswaxSampleProvider):
     assert_true("foo" in response.content)
     assert_true("bar" in response.content)
     # This should NOT go into the query history.
-    assert_equal(verify_history(self.client, fragment='test'), history_cnt,
-                 'Implicit queries should not be saved in the history')
+    assert_equal(verify_history(self.client, fragment='test'), history_cnt, 'Implicit queries should not be saved in the history')
     assert_equal(str(response.context['query_context'][0]), 'table')
     assert_equal(str(response.context['query_context'][1]), 'test:default')
 

+ 1 - 1
desktop/core/src/desktop/lib/django_mako.py

@@ -64,7 +64,7 @@ class DesktopLookup(TemplateCollection):
                             output_encoding=i18n.get_site_encoding(),
                             input_encoding=i18n.get_site_encoding(),
                             encoding_errors=ENCODING_ERRORS,
-                            default_filters=['decode.utf8', 'unicode', 'escape'],
+                            default_filters=['unicode', 'escape'],
                             imports=IMPORTS)
     # TODO(philip): Make a django_aware default filter, that understands
     # django safe strings.  See http://www.makotemplates.org/docs/filtering.html.