Pārlūkot izejas kodu

HUE-5756 [Doc2] Update test_document_trash

krish 8 gadi atpakaļ
vecāks
revīzija
ec01e0eff9

+ 8 - 12
desktop/core/src/desktop/converters.py

@@ -158,18 +158,14 @@ class DocumentConverter(object):
       LOG.info('Successfully imported %d documents' % len(self.imported_docs))
 
     # Set is_trashed field for old documents with is_trashed=None
-    try:
-      docs = Document2.objects.filter(owner=self.user, is_trashed=None)
-      for doc in docs:
-        try:
-          dirs = doc.path.split('/')
-          if len(filter(None, dirs)) > 1: # Removing empty strings from the list
-            doc.is_trashed = dirs[1] == '.Trash'
-            doc.save()
-        except Exception, e:
-          LOG.error("Failed to set is_trashed field with exception: %s" % e)
-    except ImportError, e:
-      LOG.warn('Failed to set is_trashed field for old documents')
+    docs = Document2.objects.filter(owner=self.user, is_trashed=None)
+    for doc in docs:
+      try:
+        if doc.path and doc.path != '/.Trash':
+          doc.is_trashed = doc.path.startswith('/.Trash')
+          doc.save()
+      except Exception, e:
+        LOG.exception("Failed to set is_trashed field with exception: %s" % e)
 
 
   def _get_unconverted_docs(self, content_type, with_history=False):

+ 4 - 0
desktop/core/src/desktop/tests_doc2.py

@@ -277,9 +277,11 @@ class TestDocument2(object):
     assert_equal(0, data['count'])
 
     # Delete query2.sql
+    assert_false(Document2.objects.get(uuid=query.uuid).is_trashed)
     response = self.client.post('/desktop/api2/doc/delete', {'uuid': json.dumps(query.uuid)})
     data = json.loads(response.content)
     assert_equal(0, data['status'])
+    assert_true(Document2.objects.get(uuid=query.uuid).is_trashed)
 
     response = self.client.get('/desktop/api2/doc', {'path': '/.Trash'})
     data = json.loads(response.content)
@@ -287,9 +289,11 @@ class TestDocument2(object):
     assert_equal(data['children'][0]['uuid'], query.uuid)
 
     # Delete test_dir directory w/ contents
+    assert_false(Document2.objects.get(uuid=dir.uuid).is_trashed)
     response = self.client.post('/desktop/api2/doc/delete', {'uuid': json.dumps(dir.uuid)})
     data = json.loads(response.content)
     assert_equal(0, data['status'], data)
+    assert_true(Document2.objects.get(uuid=dir.uuid).is_trashed)
 
     response = self.client.get('/desktop/api2/doc', {'path': '/.Trash'})
     data = json.loads(response.content)