소스 검색

[doc2] Implement and test recursive skip trash

Jenny Kim 9 년 전
부모
커밋
a5a9f4e
3개의 변경된 파일19개의 추가작업 그리고 8개의 파일을 삭제
  1. 1 4
      desktop/core/src/desktop/api2.py
  2. 0 2
      desktop/core/src/desktop/models.py
  3. 18 2
      desktop/core/src/desktop/tests_doc2.py

+ 1 - 4
desktop/core/src/desktop/api2.py

@@ -221,12 +221,9 @@ def delete_document(request):
   document.can_write_or_exception(request.user)
 
   if skip_trash:
-    # TODO: check if document is in the .Trash folder, if not raise exception
-    if document.is_directory and document.has_children:
-      raise PopupException(_('Directory is not empty'))
     document.delete()
   else:
-    document.trash()  # TODO: get number of docs trashed
+    document.trash()
 
   return JsonResponse({
       'status': 0,

+ 0 - 2
desktop/core/src/desktop/models.py

@@ -1067,8 +1067,6 @@ class Document2(models.Model):
     trash_dir = Directory.objects.get(name=self.TRASH_DIR, owner=self.owner)
     self.move(trash_dir, self.owner)
 
-  # TODO: erase/purge
-
   # TODO: restore
 
   def can_read(self, user):

+ 18 - 2
desktop/core/src/desktop/tests_doc2.py

@@ -211,6 +211,10 @@ class TestDocument2(object):
 
   def test_document_trash(self):
     # Create document under home and directory under home with child document
+    # /
+    #   test_dir/
+    #     query1.sql
+    #   query2.sql
     dir = Directory.objects.create(name='test_dir', owner=self.user, parent_directory=self.home_dir)
     nested_query = Document2.objects.create(name='query1.sql', type='query-hive', owner=self.user, data={}, parent_directory=dir)
     query = Document2.objects.create(name='query2.sql', type='query-hive', owner=self.user, data={}, parent_directory=self.home_dir)
@@ -220,7 +224,7 @@ class TestDocument2(object):
     data = json.loads(response.content)
     assert_equal(0, data['count'])
 
-    # Delete document
+    # Delete query2.sql
     response = self.client.post('/desktop/api2/doc/delete', {'uuid': json.dumps(query.uuid)})
     data = json.loads(response.content)
     assert_equal(0, data['status'])
@@ -230,7 +234,7 @@ class TestDocument2(object):
     assert_equal(1, data['count'])
     assert_equal(data['children'][0]['uuid'], query.uuid)
 
-    # Delete directory
+    # Delete test_dir directory w/ contents
     response = self.client.post('/desktop/api2/doc/delete', {'uuid': json.dumps(dir.uuid)})
     data = json.loads(response.content)
     assert_equal(0, data['status'], data)
@@ -239,6 +243,18 @@ class TestDocument2(object):
     data = json.loads(response.content)
     assert_equal(2, data['count'])
 
+    # Child document should be in trash too
+    response = self.client.get('/desktop/api2/docs', {'path': '/.Trash/test_dir'})
+    data = json.loads(response.content)
+    assert_equal(nested_query.uuid, data['children'][0]['uuid'])
+
+    # Skip Trash (erase) on a directory with contents should erase all children recursively
+    response = self.client.post('/desktop/api2/doc/delete', {'uuid': json.dumps(dir.uuid), 'skip_trash': json.dumps(True)})
+    data = json.loads(response.content)
+    assert_equal(0, data['status'])
+    assert_false(Document2.objects.filter(uuid=dir.uuid).exists())
+    assert_false(Document2.objects.filter(uuid=nested_query.uuid).exists())
+
     # Verify that only doc in home is .Trash
     response = self.client.get('/desktop/api2/docs', {'path': '/'})
     data = json.loads(response.content)