فهرست منبع

HUE-9185 [core] Update tests to work with gist turned on

Romain 5 سال پیش
والد
کامیت
bd447e1b40
3فایلهای تغییر یافته به همراه25 افزوده شده و 17 حذف شده
  1. 12 3
      desktop/core/src/desktop/api2_tests.py
  2. 10 10
      desktop/core/src/desktop/document2_tests.py
  3. 3 4
      desktop/core/src/desktop/tests.py

+ 12 - 3
desktop/core/src/desktop/api2_tests.py

@@ -22,13 +22,12 @@ import re
 
 from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises
 
-from useradmin.models import get_default_user_group, User
-
 from beeswax.conf import HIVE_SERVER_HOST
+from useradmin.models import get_default_user_group, User
 
 from desktop.conf import ENABLE_GIST_PREVIEW
 from desktop.lib.django_test_util import make_logged_in_client
-from desktop.models import Document2
+from desktop.models import Document2, Directory
 
 
 class TestApi2(object):
@@ -683,6 +682,16 @@ class TestDocumentGist(object):
     assert_equal('/hue/editor?gist=%(uuid)s&type=hive-query' % gist, response.url)
 
 
+  def test_gist_directory_creation(self):
+    home_dir = Directory.objects.get_home_directory(self.user)
+
+    assert_false(home_dir.children.filter(name='Gist').exists())
+
+    Document2.objects.get_gist_directory(self.user)
+
+    assert_true(home_dir.children.filter(name='Gist').exists())
+
+
   def test_get_unfurl(self):
     # Unfurling on
     f = ENABLE_GIST_PREVIEW.set_for_testing(True)

+ 10 - 10
desktop/core/src/desktop/document2_tests.py

@@ -29,20 +29,20 @@ from django.db.utils import OperationalError
 from beeswax.models import SavedQuery
 from beeswax.design import hql_query
 from notebook.models import import_saved_beeswax_query
-try:
-  from oozie.models2 import Workflow
-  has_oozie = True
-except RuntimeError:
-  has_oozie = False
 from useradmin.models import get_default_user_group, User
 
-from desktop.conf import ENABLE_GIST
 from desktop.converters import DocumentConverter
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.fs import ProxyFS
 from desktop.lib.test_utils import grant_access
 from desktop.models import Directory, Document2, Document, Document2Permission
 
+try:
+  from oozie.models2 import Workflow
+  has_oozie = True
+except RuntimeError:
+  has_oozie = False
+
 
 class MockFs(object):
   def __init__(self):
@@ -286,13 +286,13 @@ class TestDocument2(object):
     response = self.client.get('/desktop/api2/doc', {'path': '/'})
     data = json.loads(response.content)
     assert_true('children' in data)
-    assert_equal(6 if ENABLE_GIST.get() else 5, data['count'])  # This includes the 4 docs and .Trash and Gist
+    assert_equal(5, data['count'])  # This includes the 4 docs and .Trash and Gist
 
     # Test filter type
     response = self.client.get('/desktop/api2/doc', {'path': '/', 'type': ['directory']})
     data = json.loads(response.content)
     assert_equal(['directory'], data['types'])
-    assert_equal(4 if ENABLE_GIST.get() else 3, data['count'])
+    assert_equal(3, data['count'])
     assert_true(all(doc['type'] == 'directory' for doc in data['children']))
 
     # Test search text
@@ -308,7 +308,7 @@ class TestDocument2(object):
     # Test pagination with limit
     response = self.client.get('/desktop/api2/doc', {'path': '/', 'page': 2, 'limit': 2})
     data = json.loads(response.content)
-    assert_equal(6 if ENABLE_GIST.get() else 5, data['count'])
+    assert_equal(5, data['count'])
     assert_equal(2, len(data['children']))
 
 
@@ -396,7 +396,7 @@ class TestDocument2(object):
     response = self.client.get('/desktop/api2/doc', {'path': '/'})
     data = json.loads(response.content)
     assert_true('children' in data)
-    assert_equal(2 if ENABLE_GIST.get() else 1, data['count'])
+    assert_equal(1, data['count'])
     assert_true(Document2.TRASH_DIR in [f['name'] for f in data['children']])
 
 

+ 3 - 4
desktop/core/src/desktop/tests.py

@@ -57,7 +57,6 @@ import desktop.views as views
 
 from desktop.auth.backend import rewrite_user
 from desktop.appmanager import DESKTOP_APPS
-from desktop.conf import ENABLE_GIST
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.conf import validate_path
 from desktop.lib.django_util import TruncatingModel
@@ -1138,7 +1137,7 @@ class TestDocument(object):
         parent_directory=home_dir
     )
 
-    assert_equal(home_dir.children.count(), 4 if ENABLE_GIST.get() else 3)
+    assert_equal(home_dir.children.count(), 3)
 
     # Cannot create second trash directory directly as it will fail in Document2.validate()
     Document2.objects.create(owner=self.user, parent_directory=home_dir, name='second_trash_dir', type='directory')
@@ -1153,11 +1152,11 @@ class TestDocument(object):
         description='',
         parent_directory=home_dir
     )
-    assert_equal(home_dir.children.count(), 6 if ENABLE_GIST.get() else 5) # Including the second trash
+    assert_equal(home_dir.children.count(), 5) # Including the second trash
     assert_raises(Document2.MultipleObjectsReturned, Directory.objects.get, name=Document2.TRASH_DIR)
 
     test_doc1.trash()
-    assert_equal(home_dir.children.count(), 4 if ENABLE_GIST.get() else 3) # As trash documents are merged count is back to 3
+    assert_equal(home_dir.children.count(), 3) # As trash documents are merged count is back to 3
     merged_trash_dir = Directory.objects.get(name=Document2.TRASH_DIR, owner=self.user)
 
     test_doc2.trash()