Преглед на файлове

[doc2] Allow to move files into a directory

Romain Rigaux преди 9 години
родител
ревизия
6595161893
променени са 2 файла, в които са добавени 32 реда и са изтрити 1 реда
  1. 1 1
      desktop/core/src/desktop/api2.py
  2. 31 0
      desktop/core/src/desktop/tests_doc2.py

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

@@ -160,7 +160,7 @@ def move_document(request):
   if not source_doc_uuid or not destination_doc_uuid:
     raise PopupException(_('move_document requires source_doc_uuid and destination_doc_uuid'))
 
-  source = Directory.objects.get_by_uuid(uuid=source_doc_uuid)
+  source = Document2.objects.get_by_uuid(uuid=source_doc_uuid)
   destination = Directory.objects.get_by_uuid(uuid=destination_doc_uuid)
 
   # Check if user has write permissions for both source and destination

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

@@ -110,6 +110,37 @@ class TestDocument2(object):
     assert_equal(data['directory']['type'], 'directory', data)
 
 
+  def test_file_move(self):
+    source_dir = Directory.objects.create(name='test_mv_file_src', owner=self.user, parent_directory=self.home_dir)
+    target_dir = Directory.objects.create(name='test_mv_file_dst', owner=self.user, parent_directory=self.home_dir)
+    doc = Document2.objects.create(name='query1.sql', type='query-hive', owner=self.user, data={}, parent_directory=source_dir)
+
+    # Verify original paths before move operation
+    response = self.client.get('/desktop/api2/doc/get', {'uuid': source_dir.uuid})
+    data = json.loads(response.content)
+    assert_equal('/test_mv_file_src', data['path'])
+
+    response = self.client.get('/desktop/api2/doc/get', {'uuid': doc.uuid})
+    data = json.loads(response.content)
+    assert_equal('/test_mv_file_src/query1.sql', data['path'])
+
+    response = self.client.post('/desktop/api2/doc/move', {
+        'source_doc_uuid': json.dumps(doc.uuid),
+        'destination_doc_uuid': json.dumps(target_dir.uuid)
+    })
+    data = json.loads(response.content)
+    assert_equal(0, data['status'], data)
+
+    # Verify that the paths are updated
+    response = self.client.get('/desktop/api2/docs', {'uuid': source_dir.uuid})
+    data = json.loads(response.content)
+    assert_false(any(doc['uuid'] == doc.uuid for doc in data['children']), data['children'])
+
+    response = self.client.get('/desktop/api2/doc/get', {'uuid': doc.uuid})
+    data = json.loads(response.content)
+    assert_equal('/test_mv_file_dst/query1.sql', data['path'])
+
+
   def test_directory_move(self):
     source_dir = Directory.objects.create(name='test_mv', owner=self.user, parent_directory=self.home_dir)
     target_dir = Directory.objects.create(name='test_mv_dst', owner=self.user, parent_directory=self.home_dir)