def test_copy_paste_empty_folder_last(self): """ copy 'a1' to 'Nuxeo Drive Test Workspace', then 'a2' to 'Nuxeo Drive Test Workspace' """ log.debug('*** enter TestLocalPaste.test_copy_paste_empty_folder_last()') workspace_abspath = self.local_client_1._abspath('/') # copy 'temp/a1' under 'Nuxeo Drive Test Workspace' shutil.copytree(self.folder1, os.path.join(workspace_abspath, self.FOLDER_A1)) # copy 'temp/a2' under 'Nuxeo Drive Test Workspace' shutil.copytree(self.folder2, os.path.join(workspace_abspath, self.FOLDER_A2)) self.wait_sync(timeout=TEST_TIMEOUT) # check that '/Nuxeo Drive Test Workspace/a1' does exist self.assertTrue(self.local_client_1.exists(os.path.join('/', self.FOLDER_A1))) # check that '/Nuxeo Drive Test Workspace/a2' does exist self.assertTrue(self.local_client_1.exists(os.path.join('/', self.FOLDER_A2))) # check that '/Nuxeo Drive Test Workspace/a1/ has all the files children = os.listdir(os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual(len(children), self.NUMBER_OF_LOCAL_FILES, 'folder /Nuxeo Drive Test Workspace/%s has %d files (expected %d)' % (self.FOLDER_A1, len(children), self.NUMBER_OF_LOCAL_FILES)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' exists remote_ref_1 = self.local_client_1.get_remote_id(os.path.join('/', self.FOLDER_A1)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_1)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a2' exists remote_ref_2 = self.local_client_1.get_remote_id(os.path.join('/', self.FOLDER_A2)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_2)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' has all the files remote_children = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1)] self.assertEqual(len(remote_children), self.NUMBER_OF_LOCAL_FILES, 'remote folder /Nuxeo Drive Test Workspace/%s has %d files (expected %d)' % (self.FOLDER_A1, len(remote_children), self.NUMBER_OF_LOCAL_FILES)) log.debug('*** exit TestLocalPaste.test_copy_paste_empty_folder_last()')
def _moves(self, stopped=False): if stopped and not self.fake: self.engine_1.stop() # While we are started # Move one parent to the second children if len(self.tree["childs"]) < 3 or self.depth < 2: raise SkipTest("Can't execute this test on so few data") # Move root 2 in, first subchild of 1 root_2 = self.get_path(True, 1, 2) child = self.get_path(True, self.depth, 1) log.debug("Will move " + root_2 + " into " + child) if not self.fake: shutil.move(self.local_client_1._abspath(root_2), self.local_client_1._abspath(child)) root_1 = self.get_path(True, 1, 1) root_3 = self.get_path(True, 1, 3) log.debug("Will move " + root_1 + " into " + root_3) if not self.fake: shutil.move(self.local_client_1._abspath(root_1), self.local_client_1._abspath(root_3)) # Update paths child = "/" + self.get_name(True, 1, 3) + child root_2 = child + self.get_name(True, 1, 2) root_1 = root_3 + self.get_name(True, 1, 1) if stopped and not self.fake: self.engine_1.start() self.wait_sync(wait_for_async=True, timeout=self.items * 10) # Assert self._check_folder(root_3, added=[self.get_name(True, 1, 1)]) self._check_folder(child, added=[self.get_name(True, 1, 2)]) self._check_folder(root_1) self._check_folder(root_2)
def _moves(self, stopped=False): if stopped and not self.fake: self.engine_1.stop() # While we are started # Move one parent to the second children if len(self.tree["childs"]) < 3 or self.depth < 2: raise SkipTest("Can't execute this test on so few data") # Move root 2 in, first subchild of 1 root_2 = self.get_path(True, 1, 2) child = self.get_path(True, self.depth, 1) log.debug("Will move " + root_2 + " into " + child) if not self.fake: shutil.move(self.local_client_1._abspath(root_2), self.local_client_1._abspath(child)) root_1 = self.get_path(True, 1, 1) root_3 = self.get_path(True, 1, 3) log.debug("Will move " + root_1 + " into " + root_3) if not self.fake: shutil.move(self.local_client_1._abspath(root_1), self.local_client_1._abspath(root_3)) # Update paths child = "/" + self.get_name(True, 1, 3) + child root_2 = child + self.get_name(True, 1, 2) root_1 = root_3 + self.get_name(True, 1, 1) if stopped and not self.fake: self.engine_1.start() self.wait_sync(wait_for_async=True, timeout=self.items*10) # Assert self._check_folder(root_3, added=[self.get_name(True, 1, 1)]) self._check_folder(child, added=[self.get_name(True, 1, 2)]) self._check_folder(root_1) self._check_folder(root_2)
def test_local_move_folder_with_files(self): src = self.local_client_1._abspath(self.folder_path_1) dst = self.local_client_1._abspath(self.folder_path_2) shutil.move(src, dst) self.wait_sync() # Check that a1 doesn't exist anymore locally self.assertFalse(self.local_client_1.exists('/a1')) # Check local files in a2 self.assertTrue(self.local_client_1.exists('/a2')) children_2 = [child.name for child in self.local_client_1.get_children_info('/a2') if not child.folderish] self.assertEqual(len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a2 is different from original (%d)' % (len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(children_2), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # Check local files in a2/a1 self.assertTrue(self.local_client_1.exists('/a2/a1')) children_1 = [child.name for child in self.local_client_1.get_children_info('/a2/a1')] self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a1 is different from original (%d)' % (len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # Check that a1 doesn't exist anymore remotely self.assertEqual(len(self.remote_document_client_1.get_children_info(self.workspace)), 1) # Check remote files in a2 a2_remote_id = self.local_client_1.get_remote_id('/a2') self.assertIsNotNone(a2_remote_id) log.debug("Remote ref of a2: %s", a2_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a2_remote_id)) remote_children_2 = [child.name for child in self.remote_file_system_client_1.get_children_info(a2_remote_id) if not child.folderish] self.assertEqual(len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a2 is different from original (%d)' % (len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(remote_children_2), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # Check remote files in a2/a1 a1_remote_id = self.local_client_1.get_remote_id('/a2/a1') self.assertIsNotNone(a1_remote_id) log.debug("Remote ref of a1: %s", a1_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id)) remote_children_1 = [child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id)] self.assertEqual(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a1 is different from original (%d)' % (len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(remote_children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))
def setUp(self): super(TestLocalPaste, self).setUp() log.debug('*** enter TestLocalPaste.setUp()') log.debug('*** engine1 starting') self.engine_1.start() self.wait_sync(wait_for_async=True) log.debug('*** engine 1 synced') self.assertTrue(self.local_client_1.exists('/'), "Test sync root should be sync") self.workspace_abspath = self.local_client_1._abspath('/') # create folder a1 and a2 under a temp folder self.local_temp = tempfile.mkdtemp(self.TEMP_FOLDER) self.folder1 = os.path.join(self.local_temp, self.FOLDER_A1) os.makedirs(self.folder1) self.folder2 = os.path.join(self.local_temp, self.FOLDER_A2) os.makedirs(self.folder2) # add files in folder 'temp/a1' for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1): filename = self.FILENAME_PATTERN % file_num with open(os.path.join(self.folder1, filename), 'w') as f: f.write(FILE_CONTENT) log.debug('*** exit TestLocalPaste.setUp()')
def test_copy_paste_same_file(self): log.debug('*** enter TestLocalPaste.test_copy_paste_same_file()') name = self.FILENAME_PATTERN % 1 workspace_abspath = self.local_client_1._abspath('/') path = os.path.join('/', self.FOLDER_A1, name) copypath = os.path.join('/', self.FOLDER_A1, name + 'copy') # copy 'temp/a1' under 'Nuxeo Drive Test Workspace' os.mkdir(os.path.join(workspace_abspath, self.FOLDER_A1)) shutil.copy2(os.path.join(self.folder1, name), os.path.join(workspace_abspath, self.FOLDER_A1, name)) self.wait_sync(timeout=TEST_TIMEOUT) # check that '/Nuxeo Drive Test Workspace/a1' does exist self.assertTrue(self.local_client_1.exists(os.path.join('/', self.FOLDER_A1))) # check that '/Nuxeo Drive Test Workspace/a1/ has all the files children = os.listdir(os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual(len(children), 1) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' exists remote_ref_1 = self.local_client_1.get_remote_id(os.path.join('/', self.FOLDER_A1)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_1)) remote_children = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1)] self.assertEqual(len(remote_children), 1) remote_id = self.local_client_1.get_remote_id(path) log.debug('*** copy file TestLocalPaste.test_copy_paste_same_file()') shutil.copy2(self.local_client_1._abspath(path), self.local_client_1._abspath(copypath)) self.local_client_1.set_remote_id(copypath, remote_id) log.debug('*** wait for sync TestLocalPaste.test_copy_paste_same_file()') self.wait_sync(timeout=TEST_TIMEOUT) remote_children = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1)] self.assertEqual(len(remote_children), 2) children = os.listdir(os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual(len(children), 2) log.debug('*** exit TestLocalPaste.test_copy_paste_same_file()')
def setUp(self): super(TestLocalCreateFolders, self).setUp() log.debug('*** enter TestLocalCreateFolders.setUp() ***') log.debug('*** engine1 starting ***') self.engine_1.get_local_watcher().set_windows_queue_threshold(1000) self.engine_1.start() self.wait_sync(wait_for_async=True) log.debug('*** engine1 synced ***') log.debug("full local root path %s", self.local_root_client_1.get_info("/")) self.assertTrue(self.local_root_client_1.exists('/Nuxeo Drive Test Workspace'), "Nuxeo Drive Test Workspace should be sync") log.debug('*** exit TestLocalCreateFolders.setUp() ***')
def _copies(self, stopped=False): if stopped and not self.fake: self.engine_1.stop() # Copy root 2 in, first subchild of 1 root_2 = self.get_path(True, 1, 2) child = self.get_path(True, self.depth, 1) log.debug("Will copy " + root_2 + " into " + child) if not self.fake: shutil.copytree( self.local_client_1._abspath(root_2), self.local_client_1._abspath(child + self.get_name(True, 1, 2))) root_1 = self.get_path(True, 1, 1) root_3 = self.get_path(True, 1, 3) # new copies root_4 = self.get_path(True, 1, self.num_folders + 1) root_5 = self.get_path(True, 1, self.num_folders + 2) log.debug("Will copy " + root_1 + " into " + root_3) if not self.fake: shutil.copytree( self.local_client_1._abspath(root_1), self.local_client_1._abspath(root_3 + self.get_name(True, 1, 1))) log.debug("Will copy " + root_3 + " into " + root_4) log.debug("Will copy " + root_3 + " into " + root_5) shutil.copytree(self.local_client_1._abspath(root_3), self.local_client_1._abspath(root_4)) shutil.copytree(self.local_client_1._abspath(root_3), self.local_client_1._abspath(root_5)) # Update paths child = "/" + self.get_name(True, 1, 3) + child root_2 = child + self.get_name(True, 1, 2) root_1 = root_3 + self.get_name(True, 1, 1) root_1_path = self.local_client_1._abspath(root_1) child_path = self.local_client_1._abspath(child) added_files = [] # Copies files from one folder to another for name in os.listdir(child_path): if not os.path.isfile(os.path.join(child_path, name)): continue shutil.copy(os.path.join(child_path, name), root_1_path) added_files.append(name) if stopped and not self.fake: self.engine_1.start() self.wait_sync(wait_for_async=True, timeout=self.items * 10) # Assert self._check_folder(root_3, added=[self.get_name(True, 1, 1)]) self._check_folder(child, added=[self.get_name(True, 1, 2)]) self._check_folder(root_1, added=added_files) self._check_folder(root_2) # check original copied self._check_folder(self.get_path(True, 1, 1)) self._check_folder(self.get_path(True, 1, 2)) self._check_folder(self.get_path(True, 1, self.num_folders + 1), added=[self.get_name(True, 1, 1)]) self._check_folder(self.get_path(True, 1, self.num_folders + 2), added=[self.get_name(True, 1, 1)])
def setUp(self): super(TestLocalCreateFolders, self).setUp() log.debug('*** enter TestLocalCreateFolders.setUp() ***') log.debug('*** engine1 starting ***') self.engine_1.get_local_watcher().set_windows_queue_threshold(1000) self.engine_1.start() self.wait_sync(wait_for_async=True) log.debug('*** engine1 synced ***') log.debug("full local root path %s", self.local_root_client_1.get_info("/")) self.assertTrue( self.local_root_client_1.exists('/Nuxeo Drive Test Workspace'), "Nuxeo Drive Test Workspace should be sync") log.debug('*** exit TestLocalCreateFolders.setUp() ***')
def test_copy_paste_empty_folder_last(self): log.debug( '*** enter TestLocalPaste.test_copy_paste_empty_folder_last()') workspace_abspath = self.local_client_1._abspath('/') # copy 'temp/a1' under 'Nuxeo Drive Test Workspace' shutil.copytree(self.folder1, os.path.join(workspace_abspath, self.FOLDER_A1)) # copy 'temp/a2' under 'Nuxeo Drive Test Workspace' shutil.copytree(self.folder2, os.path.join(workspace_abspath, self.FOLDER_A2)) self.wait_sync(timeout=TEST_TIMEOUT) # check that '/Nuxeo Drive Test Workspace/a1' does exist self.assertTrue( self.local_client_1.exists(os.path.join('/', self.FOLDER_A1))) # check that '/Nuxeo Drive Test Workspace/a2' does exist self.assertTrue( self.local_client_1.exists(os.path.join('/', self.FOLDER_A2))) # check that '/Nuxeo Drive Test Workspace/a1/ has all the files children = os.listdir( os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual( len(children), self.NUMBER_OF_LOCAL_FILES, 'folder /Nuxeo Drive Test Workspace/%s has %d files (expected %d)' % (self.FOLDER_A1, len(children), self.NUMBER_OF_LOCAL_FILES)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' exists remote_ref_1 = self.local_client_1.get_remote_id( os.path.join('/', self.FOLDER_A1)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_1)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a2' exists remote_ref_2 = self.local_client_1.get_remote_id( os.path.join('/', self.FOLDER_A2)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_2)) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' has all the files remote_children = [ remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1) ] self.assertEqual( len(remote_children), self.NUMBER_OF_LOCAL_FILES, 'remote folder /Nuxeo Drive Test Workspace/%s has %d files (expected %d)' % (self.FOLDER_A1, len(remote_children), self.NUMBER_OF_LOCAL_FILES)) log.debug( '*** exit TestLocalPaste.test_copy_paste_empty_folder_last()')
def setUp(self): """ 1. Create folder a1 in Nuxeo Drive Test Workspace sycn root 2. Create folder a2 in Nuxeo Drive Test Workspace sycn root 3. Add 10 image files in a1 """ self.engine_1.start() self.wait_sync(wait_for_async=True) self.engine_1.stop() # Create a1 and a2 self.folder_path_1 = self.local_client_1.make_folder(u'/', u'a1') self.folder_path_2 = self.local_client_1.make_folder(u'/', u'a2') # Add image files to a1 abs_folder_path_1 = self.local_client_1._abspath(self.folder_path_1) for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1): file_name = self.FILE_NAME_PATTERN % (file_num, 'jpg') file_path = os.path.join(abs_folder_path_1, file_name) self.generate_random_jpg(file_path, random.randint(1000, 3000)) log.debug('Local test files created in a1') self.engine_1.start() self.wait_sync(timeout=60, wait_win=True) # Check local files in a1 self.assertTrue(self.local_client_1.exists('/a1')) children_1 = [child.name for child in self.local_client_1.get_children_info('/a1')] self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a1 is different from original (%d)' % (len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # Check remote files in a1 a1_remote_id = self.local_client_1.get_remote_id('/a1') self.assertIsNotNone(a1_remote_id) log.debug("Remote ref of a1: %s", a1_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id)) remote_children_1 = [child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id)] self.assertEqual(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a1 is different from original (%d)' % (len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(remote_children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)]))
def _copies(self, stopped=False): if stopped and not self.fake: self.engine_1.stop() # Copy root 2 in, first subchild of 1 root_2 = self.get_path(True, 1, 2) child = self.get_path(True, self.depth, 1) log.debug("Will copy " + root_2 + " into " + child) if not self.fake: shutil.copytree(self.local_client_1._abspath(root_2), self.local_client_1._abspath(child + self.get_name(True, 1, 2))) root_1 = self.get_path(True, 1, 1) root_3 = self.get_path(True, 1, 3) # new copies root_4 = self.get_path(True, 1, self.num_folders + 1) root_5 = self.get_path(True, 1, self.num_folders + 2) log.debug("Will copy " + root_1 + " into " + root_3) if not self.fake: shutil.copytree(self.local_client_1._abspath(root_1), self.local_client_1._abspath(root_3+self.get_name(True, 1, 1))) log.debug("Will copy " + root_3 + " into " + root_4) log.debug("Will copy " + root_3 + " into " + root_5) shutil.copytree(self.local_client_1._abspath(root_3), self.local_client_1._abspath(root_4)) shutil.copytree(self.local_client_1._abspath(root_3), self.local_client_1._abspath(root_5)) # Update paths child = "/" + self.get_name(True, 1, 3) + child root_2 = child + self.get_name(True, 1, 2) root_1 = root_3 + self.get_name(True, 1, 1) root_1_path = self.local_client_1._abspath(root_1) child_path = self.local_client_1._abspath(child) added_files = [] # Copies files from one folder to another for name in os.listdir(child_path): if not os.path.isfile(os.path.join(child_path, name)): continue shutil.copy(os.path.join(child_path, name), root_1_path) added_files.append(name) if stopped and not self.fake: self.engine_1.start() self.wait_sync(wait_for_async=True, timeout=self.items*10) # Assert self._check_folder(root_3, added=[self.get_name(True, 1, 1)]) self._check_folder(child, added=[self.get_name(True, 1, 2)]) self._check_folder(root_1, added=added_files) self._check_folder(root_2) # check original copied self._check_folder(self.get_path(True, 1, 1)) self._check_folder(self.get_path(True, 1, 2)) self._check_folder(self.get_path(True, 1, self.num_folders+1), added=[self.get_name(True, 1, 1)]) self._check_folder(self.get_path(True, 1, self.num_folders+2), added=[self.get_name(True, 1, 1)])
def test_copy_paste_same_file(self): log.debug('*** enter TestLocalPaste.test_copy_paste_same_file()') name = self.FILENAME_PATTERN % 1 workspace_abspath = self.local_client_1._abspath('/') path = os.path.join('/', self.FOLDER_A1, name) copypath = os.path.join('/', self.FOLDER_A1, name + 'copy') # copy 'temp/a1' under 'Nuxeo Drive Test Workspace' os.mkdir(os.path.join(workspace_abspath, self.FOLDER_A1)) shutil.copy2(os.path.join(self.folder1, name), os.path.join(workspace_abspath, self.FOLDER_A1, name)) self.wait_sync(timeout=TEST_TIMEOUT) # check that '/Nuxeo Drive Test Workspace/a1' does exist self.assertTrue( self.local_client_1.exists(os.path.join('/', self.FOLDER_A1))) # check that '/Nuxeo Drive Test Workspace/a1/ has all the files children = os.listdir( os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual(len(children), 1) # check that remote (DM) 'Nuxeo Drive Test Workspace/a1' exists remote_ref_1 = self.local_client_1.get_remote_id( os.path.join('/', self.FOLDER_A1)) self.assertTrue(self.remote_file_system_client_1.exists(remote_ref_1)) remote_children = [ remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1) ] self.assertEqual(len(remote_children), 1) remote_id = self.local_client_1.get_remote_id(path) log.debug('*** copy file TestLocalPaste.test_copy_paste_same_file()') shutil.copy2(self.local_client_1._abspath(path), self.local_client_1._abspath(copypath)) self.local_client_1.set_remote_id(copypath, remote_id) log.debug( '*** wait for sync TestLocalPaste.test_copy_paste_same_file()') self.wait_sync(timeout=TEST_TIMEOUT) remote_children = [ remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(remote_ref_1) ] self.assertEqual(len(remote_children), 2) children = os.listdir( os.path.join(self.workspace_abspath, self.FOLDER_A1)) self.assertEqual(len(children), 2) log.debug('*** exit TestLocalPaste.test_copy_paste_same_file()')
def create(self, stopped=True, wait_for_sync=True): self.fake = False if not self.fake: self.engine_1.start() self.wait_sync() if not stopped: self.engine_1.stop() self.items = 0 values = None if "TEST_VOLUME" in os.environ: values = os.environ["TEST_VOLUME"].split(",") else: # Deactivate if needed raise SkipTest( "Deactivate if not launch on purpose with TEST_VOLUME set") #pass if values is None or len(values) < 3: # Low volume by default to stick to 1h values = "3, 10, 2".split(",") self.fmt = ["", "", ""] for i in range(0, 3): self.fmt[i] = "%0" + str(self.pow10floor(values[i])) + "d" self.depth = int(values[2]) self.num_files = int(values[1]) self.num_folders = int(values[0]) self.tree = dict() self.tree["childs"] = dict() self.tree["path"] = "/" log.debug("Generating in: " + self.local_client_1._abspath('/')) self.create_tree(self.num_folders, self.num_files, self.depth, self.tree) log.debug("Generated done in: " + self.local_client_1._abspath('/')) if not self.fake: if not stopped: log.debug('*** engine1 starting') self.engine_1.start() if wait_for_sync: self.wait_sync(timeout=self.items * 10) log.debug('*** engine 1 synced')
def create(self, stopped=True, wait_for_sync=True): self.fake = False if not self.fake: self.engine_1.start() self.wait_sync() if not stopped: self.engine_1.stop() self.items = 0 values = None if "TEST_VOLUME" in os.environ: values = os.environ["TEST_VOLUME"].split(",") else: # Deactivate if needed raise SkipTest("Deactivate if not launch on purpose with TEST_VOLUME set") #pass if values is None or len(values) < 3: # Low volume by default to stick to 1h values = "3, 10, 2".split(",") self.fmt = ["", "", ""] for i in range(0,3): self.fmt[i] = "%0" + str(self.pow10floor(values[i])) + "d" self.depth = int(values[2]) self.num_files = int(values[1]) self.num_folders = int(values[0]) self.tree = dict() self.tree["childs"] = dict() self.tree["path"] = "/" log.debug("Generating in: " + self.local_client_1._abspath('/')) self.create_tree(self.num_folders, self.num_files, self.depth, self.tree) log.debug("Generated done in: " + self.local_client_1._abspath('/')) if not self.fake: if not stopped: log.debug('*** engine1 starting') self.engine_1.start() if wait_for_sync: self.wait_sync(timeout=self.items*10) log.debug('*** engine 1 synced')
def _local_copy_paste_files(self, stopped=False): log.debug('*** enter TestLocalCopyPaste.test_local_copy_paste_files() ***') if not stopped: self.engine_1.start() # copy all children (files) of A to B src = self.local_root_client_1._abspath(self.folder_path_1) dst = self.local_root_client_1._abspath(self.folder_path_2) for f in os.listdir(src): shutil.copy(os.path.join(src, f), dst) if stopped: self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine1 synced ***') # expect local 'Nuxeo Drive Test Workspace/A' to contain all the files abs_folder_path_1 = self.local_root_client_1._abspath(self.folder_path_1) self.assertTrue(os.path.exists(abs_folder_path_1)) children_1 = os.listdir(abs_folder_path_1) postcondition1 = len(children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition1_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_1), self.folder_path_1, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_expected = set(self.local_files_list) local_files_actual = set(children_1) postcondition2 = local_files_actual == local_files_expected postcondition2_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_1 if not postcondition2: unexpected_actual_files = '\n'.join(local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(local_files_actual)) postcondition2_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % (unexpected_actual_files, missing_expected_files) # expect local 'Nuxeo Drive Test Workspace/B' to contain also the same files abs_folder_path_2 = self.local_root_client_1._abspath(self.folder_path_2) self.assertTrue(os.path.exists(abs_folder_path_2)) children_2 = os.listdir(abs_folder_path_2) postcondition3 = len(children_2) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition3_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_2), self.folder_path_2, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_actual = set(children_2) postcondition4 = local_files_actual == local_files_expected postcondition4_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_2 if not postcondition4: unexpected_actual_files = '\n'.join(local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(local_files_actual)) postcondition4_error += '\nunexpected files:\n%s\n\nmissing files:\n%s' % (unexpected_actual_files, missing_expected_files) # expect remote 'Nuxeo Drive Test Workspace/A' to contain all the files # just compare the names remote_ref_1_name = self.remote_file_system_client_1.get_info(self.remote_ref_1).name remote_children_1 = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(self.remote_ref_1)] postcondition5 = len(remote_children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition5_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_1), remote_ref_1_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_1) postcondition6 = remote_files_actual == remote_files_expected postcondition6_error = ('remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_1_name) if not postcondition6: unexpected_actual_files = '\n'.join(local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(remote_files_actual)) postcondition6_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % (unexpected_actual_files, missing_expected_files) # expect remote 'Nuxeo Drive Test Workspace/B' to contain all the files # just compare the names remote_ref_2_name = self.remote_file_system_client_1.get_info(self.remote_ref_2).name remote_children_2 = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(self.remote_ref_2)] postcondition7 = len(remote_children_2) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition7_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_2), remote_ref_2_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_2) postcondition8 = remote_files_actual == remote_files_expected postcondition8_error = ('remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_2_name) if not postcondition8: unexpected_actual_files = '\n'.join(local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(remote_files_actual)) postcondition6_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % (unexpected_actual_files, missing_expected_files) # output the results before asserting if not postcondition1: log.debug(postcondition1_error) if not postcondition2: log.debug(postcondition2_error) if not postcondition3: log.debug(postcondition3_error) if not postcondition4: log.debug(postcondition4_error) if not postcondition5: log.debug(postcondition5_error) if not postcondition6: log.debug(postcondition6_error) if not postcondition7: log.debug(postcondition7_error) if not postcondition8: log.debug(postcondition8_error) self.assertTrue(postcondition1, postcondition1_error) self.assertTrue(postcondition2, postcondition2_error) self.assertTrue(postcondition3, postcondition3_error) self.assertTrue(postcondition4, postcondition4_error) self.assertTrue(postcondition5, postcondition5_error) self.assertTrue(postcondition6, postcondition6_error) self.assertTrue(postcondition7, postcondition7_error) self.assertTrue(postcondition8, postcondition8_error) log.debug('*** exit TestLocalCopyPaste.test_local_copy_paste_files() ***')
def _move_and_copy_paste_folder(self, folder_1, folder_2, target_folder, stopped=True): ''' /folder_1 /folder_2 /target_folder Will move /folder1 inside /folder2/ as /folder2/folder1 copy /folder2/folder1 into /target_folder/ ''' if stopped: self.engine_1.stop() src = self.local_client_1._abspath(folder_1) dst = self.local_client_1._abspath(folder_2) new_path = os.path.join(folder_2, os.path.basename(folder_1)) copy_path = os.path.join(target_folder, os.path.basename(folder_1)) log.debug("*** shutil move") shutil.move(src, dst) # check that 'Nuxeo Drive Test Workspace/a1' does not exist anymore self.assertFalse(self.local_client_1.exists(folder_1)) # check that 'Nuxeo Drive Test Workspace/a2/a1' now exists self.assertTrue(self.local_client_1.exists(new_path)) log.debug('*** shutil copy') # copy the 'Nuxeo Drive Test Workspace/a2/a1' tree back under 'Nuxeo Drive Test Workspace' shutil.copytree(self.local_client_1._abspath(new_path), self.local_client_1._abspath(copy_path)) if stopped: self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine 1 synced') # asserts # expect '/a2/a1' to contain the files self.assertTrue(os.path.exists(self.local_client_1._abspath(new_path))) children_1 = os.listdir(self.local_client_1._abspath(new_path)) self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d) in "%s" is different from original (%d)' % (len(children_1), new_path, self.NUMBER_OF_LOCAL_FILES)) self.assertEqual(set(children_1), set(['local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), 'file names are different') # expect 'Nuxeo Drive Test Workspace/a1' to contain also the files self.assertTrue(os.path.exists(self.local_client_1._abspath(copy_path))) children_2 = os.listdir(self.local_client_1._abspath(copy_path)) self.assertEqual(len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d)in "%s" is different from original (%d)' % (len(children_2), copy_path, self.NUMBER_OF_LOCAL_FILES)) self.assertEqual(set(children_2), set(['local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), 'file names are different') # verify the remote one a1copy_uid = self.local_client_1.get_remote_id(copy_path) self.assertIsNotNone(a1copy_uid) a1_uid = self.local_client_1.get_remote_id(new_path) self.assertIsNotNone(a1_uid) try: log.debug("%s and %s: %s/%s", new_path, copy_path, a1_uid, a1copy_uid) children_1 = self.remote_file_system_client_1.get_children_info(a1_uid) children_2 = self.remote_file_system_client_1.get_children_info(a1copy_uid) log.debug("Children1: %r", children_1) log.debug("Children2: %r", children_2) except: pass self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_1), new_path, self.NUMBER_OF_LOCAL_FILES)) children_1_name = set() for child in children_1: children_1_name.add(child.name) self.assertEqual(set(children_1_name), set(['local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), 'file names are different') self.assertEqual(len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_2), copy_path, self.NUMBER_OF_LOCAL_FILES)) children_2_name = set() for child in children_2: children_2_name.add(child.name) self.assertEqual(set(children_2_name), set(['local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), 'file names are different') log.debug('*** exit MultipleFilesTestCase._move_and_copy_paste_folder')
def test_local_create_folders_and_children_files(self): log.debug( '*** enter TestLocalCreateFolders.test_local_create_folders_and_children_files() ***' ) # create folder A self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_1) self.folder_path_1 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_1) # add text files in folder 'Nuxeo Drive Test Workspace/A' self.local_files_list = [] for file_num in range(1, self.NUMBER_OF_LOCAL_TEXT_FILES + 1): filename = self.FILE_NAME_PATTERN % (file_num, 'txt') self.local_root_client_1.make_file(self.folder_path_1, filename, FILE_CONTENT) self.local_files_list.append(filename) test_resources_path = self._get_test_resources_path() if test_resources_path is None: test_resources_path = 'tests/resources' self.test_doc_path = os.path.join( test_resources_path, TestLocalCreateFolders.TEST_DOC_RESOURCE) # add image files in folder 'Nuxeo Drive Test Workspace/A' abs_folder_path_1 = self.local_root_client_1._abspath( self.folder_path_1) for file_num in range(self.NUMBER_OF_LOCAL_TEXT_FILES + 1, self.NUMBER_OF_LOCAL_FILES_TOTAL + 1): filename = self.FILE_NAME_PATTERN % ( file_num, os.path.splitext(self.TEST_DOC_RESOURCE)[1]) dst_path = os.path.join(abs_folder_path_1, filename) shutil.copyfile(self.test_doc_path, dst_path) self.local_files_list.append(filename) log.debug('local test files created in Nuxeo Drive Test Workspace/A') # create folder B self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_2) self.folder_path_2 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_2) # wait for sync self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine1 synced ***') # get remote folders reference ids self.remote_ref_1 = self.local_root_client_1.get_remote_id( self.folder_path_1) self.assertIsNotNone(self.remote_ref_1) self.remote_ref_2 = self.local_root_client_1.get_remote_id( self.folder_path_2) self.assertIsNotNone(self.remote_ref_2) self.assertTrue( self.remote_file_system_client_1.exists(self.remote_ref_1), 'remote folder for %s does not exist' % self.folder_path_1) self.assertTrue( self.remote_file_system_client_1.exists(self.remote_ref_2), 'remote folder for %s does not exist' % self.folder_path_2) self.assertEquals( len( self.remote_file_system_client_1.get_children_info( self.remote_ref_1)), self.NUMBER_OF_LOCAL_FILES_TOTAL) # expect local 'Nuxeo Drive Test Workspace/A' to contain all the files abs_folder_path_1 = self.local_root_client_1._abspath( self.folder_path_1) self.assertTrue(os.path.exists(abs_folder_path_1)) children_1 = os.listdir(abs_folder_path_1) postcondition1 = len(children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition1_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_1), self.folder_path_1, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_expected = set(self.local_files_list) local_files_actual = set(children_1) postcondition2 = local_files_actual == local_files_expected postcondition2_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_1 if not postcondition2: unexpected_actual_files = '\n'.join( local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(local_files_actual)) postcondition2_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % ( unexpected_actual_files, missing_expected_files) # expect local 'Nuxeo Drive Test Workspace/B' to exist abs_folder_path_2 = self.local_root_client_1._abspath( self.folder_path_2) self.assertTrue(os.path.exists(abs_folder_path_2)) # expect remote 'Nuxeo Drive Test Workspace/A' to contain all the files # just compare the names remote_ref_1_name = self.remote_file_system_client_1.get_info( self.remote_ref_1).name remote_children_1 = [ remote_info.name for remote_info in self. remote_file_system_client_1.get_children_info(self.remote_ref_1) ] postcondition3 = len( remote_children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition3_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_1), remote_ref_1_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_1) postcondition4 = remote_files_actual == remote_files_expected postcondition4_error = ( 'remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_1_name) if not postcondition4: unexpected_actual_files = '\n'.join( local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(remote_files_actual)) postcondition4_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % ( unexpected_actual_files, missing_expected_files) # output the results before asserting if not postcondition1: log.debug(postcondition1_error) if not postcondition2: log.debug(postcondition2_error) if not postcondition3: log.debug(postcondition3_error) if not postcondition4: log.debug(postcondition4_error) self.assertTrue(postcondition1, postcondition1_error) self.assertTrue(postcondition2, postcondition2_error) self.assertTrue(postcondition3, postcondition3_error) self.assertTrue(postcondition4, postcondition4_error) log.debug( '*** exit TestLocalCreateFolders.test_local_create_folders_and_children_files() ***' )
def setUp(self): super(MultipleFilesTestCase, self).setUp() log.debug('*** enter MultipleFilesTestCase.setUp()') log.debug('*** engine1 starting') self.engine_1.start() self.wait_sync() log.debug('*** engine 1 synced') log.debug("full local root path %s", self.local_client_1.get_info("/")) # create folder a1 self.local_client_1.make_folder("/", ur'a1') self.folder_path_1 = os.path.join("/", 'a1') # add 100 files in folder 'Nuxeo Drive Test Workspace/a1' for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1): self.local_client_1.make_file(self.folder_path_1, 'local%04d.txt' % file_num, FILE_CONTENT) log.debug('local test files created') # create folder a2 self.local_client_1.make_folder("/", ur'a2') self.folder_path_2 = os.path.join("/", 'a2') self.folder_path_3 = os.path.join("/", 'a3') self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** exit MultipleFilesTestCase.setUp()')
def test_delay(self): sleep_time = 3 # Push two items with a delay of 1s queue = BlacklistQueue(delay=1) interval1 = queue.push(1, "Item1") interval2 = queue.push(2, "Item2") log.debug('interval1=%d', interval1) log.debug('interval2=%d', interval2) log.debug('queue:\n%s', str(queue)) # Verify no item is returned back before 1s item = queue.get() self.assertIsNone(item) sleep(sleep_time) # Verify we get the two items now item = queue.get() self.assertIsNotNone(item) self.assertEquals(item.get(), "Item1") self.assertEquals(item.get_id(), 1) item = queue.get() self.assertIsNotNone(item) self.assertEquals(item.get(), "Item2") self.assertEquals(item.get_id(), 2) self.assertEquals(item._count, 1) # Repush item without increasing delay queue.repush(item, increase_wait=False) item = queue.get() self.assertIsNone(item) sleep(sleep_time) # We should get the repushed item after 1s wait item = queue.get() self.assertIsNotNone(item) self.assertEquals(item.get(), "Item2") self.assertEquals(item.get_id(), 2) self.assertEquals(item._count, 2) # Repush item with increase interval3 = queue.push(3, "Item3") log.debug('interval3=%d', interval3) item = queue.get() self.assertIsNone(item) sleep(sleep_time) # Verify we get the item now item = queue.get() self.assertIsNotNone(item) self.assertEquals(item.get(), "Item3") self.assertEquals(item.get_id(), 3) log.debug('queue:\n%s', str(queue)) for i in range(1, 3): queue.repush(item, increase_wait=True) log.debug('item after repush:\n%s', str(item)) log.debug('queue after repush:\n%s', str(queue)) # sleep time should be at least 2 ** i + 20% min_sleep_time = int(0.8 * 2 ** i) - 1 max_sleep_time = int(1.2 * 2 ** i) + 2 if min_sleep_time < 0: min_sleep_time = 0 log.debug('min sleep time=%d', min_sleep_time) log.debug('max sleep time=%d', max_sleep_time) if min_sleep_time > 0: log.debug('sleep %d', min_sleep_time) sleep(min_sleep_time) max_sleep_time -= min_sleep_time item = queue.get() self.assertIsNone(item) log.debug('sleep %d', max_sleep_time) sleep(max_sleep_time) item = queue.get() self.assertIsNotNone(item) self.assertEquals(item.get(), "Item3") self.assertEquals(item.get_id(), 3) self.assertEquals(item._count, i + 1)
def test_local_create_folders_and_children_files(self): log.debug('*** enter TestLocalCreateFolders.test_local_create_folders_and_children_files() ***') # create folder A self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_1) self.folder_path_1 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_1) # add text files in folder 'Nuxeo Drive Test Workspace/A' self.local_files_list = [] for file_num in range(1, self.NUMBER_OF_LOCAL_TEXT_FILES + 1): filename = self.FILE_NAME_PATTERN % (file_num, 'txt') self.local_root_client_1.make_file(self.folder_path_1, filename, FILE_CONTENT) self.local_files_list.append(filename) test_resources_path = self._get_test_resources_path() if test_resources_path is None: test_resources_path = 'tests/resources' self.test_doc_path = os.path.join(test_resources_path, TestLocalCreateFolders.TEST_DOC_RESOURCE) # add image files in folder 'Nuxeo Drive Test Workspace/A' abs_folder_path_1 = self.local_root_client_1._abspath(self.folder_path_1) for file_num in range(self.NUMBER_OF_LOCAL_TEXT_FILES + 1, self.NUMBER_OF_LOCAL_FILES_TOTAL + 1): filename = self.FILE_NAME_PATTERN % (file_num, os.path.splitext(self.TEST_DOC_RESOURCE)[1]) dst_path = os.path.join(abs_folder_path_1, filename) shutil.copyfile(self.test_doc_path, dst_path) self.local_files_list.append(filename) log.debug('local test files created in Nuxeo Drive Test Workspace/A') # create folder B self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_2) self.folder_path_2 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_2) # wait for sync self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine1 synced ***') # get remote folders reference ids self.remote_ref_1 = self.local_root_client_1.get_remote_id(self.folder_path_1) self.assertIsNotNone(self.remote_ref_1) self.remote_ref_2 = self.local_root_client_1.get_remote_id(self.folder_path_2) self.assertIsNotNone(self.remote_ref_2) self.assertTrue(self.remote_file_system_client_1.exists(self.remote_ref_1), 'remote folder for %s does not exist' % self.folder_path_1) self.assertTrue(self.remote_file_system_client_1.exists(self.remote_ref_2), 'remote folder for %s does not exist' % self.folder_path_2) self.assertEquals(len(self.remote_file_system_client_1.get_children_info(self.remote_ref_1)), self.NUMBER_OF_LOCAL_FILES_TOTAL) # expect local 'Nuxeo Drive Test Workspace/A' to contain all the files abs_folder_path_1 = self.local_root_client_1._abspath(self.folder_path_1) self.assertTrue(os.path.exists(abs_folder_path_1)) children_1 = os.listdir(abs_folder_path_1) postcondition1 = len(children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition1_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_1), self.folder_path_1, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_expected = set(self.local_files_list) local_files_actual = set(children_1) postcondition2 = local_files_actual == local_files_expected postcondition2_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_1 if not postcondition2: unexpected_actual_files = '\n'.join(local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(local_files_actual)) postcondition2_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % (unexpected_actual_files, missing_expected_files) # expect local 'Nuxeo Drive Test Workspace/B' to exist abs_folder_path_2 = self.local_root_client_1._abspath(self.folder_path_2) self.assertTrue(os.path.exists(abs_folder_path_2)) # expect remote 'Nuxeo Drive Test Workspace/A' to contain all the files # just compare the names remote_ref_1_name = self.remote_file_system_client_1.get_info(self.remote_ref_1).name remote_children_1 = [remote_info.name for remote_info in self.remote_file_system_client_1.get_children_info(self.remote_ref_1)] postcondition3 = len(remote_children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition3_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_1), remote_ref_1_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_1) postcondition4 = remote_files_actual == remote_files_expected postcondition4_error = ('remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_1_name) if not postcondition4: unexpected_actual_files = '\n'.join(local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join(local_files_expected.difference(remote_files_actual)) postcondition4_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % (unexpected_actual_files, missing_expected_files) # output the results before asserting if not postcondition1: log.debug(postcondition1_error) if not postcondition2: log.debug(postcondition2_error) if not postcondition3: log.debug(postcondition3_error) if not postcondition4: log.debug(postcondition4_error) self.assertTrue(postcondition1, postcondition1_error) self.assertTrue(postcondition2, postcondition2_error) self.assertTrue(postcondition3, postcondition3_error) self.assertTrue(postcondition4, postcondition4_error) log.debug('*** exit TestLocalCreateFolders.test_local_create_folders_and_children_files() ***')
def _move_and_copy_paste_folder(self, folder_1, folder_2, target_folder, stopped=True): ''' /folder_1 /folder_2 /target_folder Will move /folder1 inside /folder2/ as /folder2/folder1 copy /folder2/folder1 into /target_folder/ ''' if stopped: self.engine_1.stop() src = self.local_client_1._abspath(folder_1) dst = self.local_client_1._abspath(folder_2) new_path = os.path.join(folder_2, os.path.basename(folder_1)) copy_path = os.path.join(target_folder, os.path.basename(folder_1)) log.debug("*** shutil move") shutil.move(src, dst) # check that 'Nuxeo Drive Test Workspace/a1' does not exist anymore self.assertFalse(self.local_client_1.exists(folder_1)) # check that 'Nuxeo Drive Test Workspace/a2/a1' now exists self.assertTrue(self.local_client_1.exists(new_path)) log.debug('*** shutil copy') # copy the 'Nuxeo Drive Test Workspace/a2/a1' tree back under 'Nuxeo Drive Test Workspace' shutil.copytree(self.local_client_1._abspath(new_path), self.local_client_1._abspath(copy_path)) if stopped: self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine 1 synced') # asserts # expect '/a2/a1' to contain the files self.assertTrue(os.path.exists(self.local_client_1._abspath(new_path))) children_1 = os.listdir(self.local_client_1._abspath(new_path)) self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d) in "%s" is different from original (%d)' % (len(children_1), new_path, self.NUMBER_OF_LOCAL_FILES)) self.assertEqual( set(children_1), set([ 'local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1) ]), 'file names are different') # expect 'Nuxeo Drive Test Workspace/a1' to contain also the files self.assertTrue(os.path.exists( self.local_client_1._abspath(copy_path))) children_2 = os.listdir(self.local_client_1._abspath(copy_path)) self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d)in "%s" is different from original (%d)' % (len(children_2), copy_path, self.NUMBER_OF_LOCAL_FILES)) self.assertEqual( set(children_2), set([ 'local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1) ]), 'file names are different') # verify the remote one a1copy_uid = self.local_client_1.get_remote_id(copy_path) self.assertIsNotNone(a1copy_uid) a1_uid = self.local_client_1.get_remote_id(new_path) self.assertIsNotNone(a1_uid) try: log.debug("%s and %s: %s/%s", new_path, copy_path, a1_uid, a1copy_uid) children_1 = self.remote_file_system_client_1.get_children_info( a1_uid) children_2 = self.remote_file_system_client_1.get_children_info( a1copy_uid) log.debug("Children1: %r", children_1) log.debug("Children2: %r", children_2) except: pass self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_1), new_path, self.NUMBER_OF_LOCAL_FILES)) children_1_name = set() for child in children_1: children_1_name.add(child.name) self.assertEqual( set(children_1_name), set([ 'local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1) ]), 'file names are different') self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_2), copy_path, self.NUMBER_OF_LOCAL_FILES)) children_2_name = set() for child in children_2: children_2_name.add(child.name) self.assertEqual( set(children_2_name), set([ 'local%04d.txt' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1) ]), 'file names are different') log.debug('*** exit MultipleFilesTestCase._move_and_copy_paste_folder')
def tearDown(self): log.debug('*** enter TestLocalCopyPaste.tearDown() ***') # list content of folder A abs_folder_path_1 = self.local_root_client_1._abspath( self.folder_path_1) log.debug('content of folder "%s"', abs_folder_path_1) for f in os.listdir(abs_folder_path_1): log.debug(f) # list content of folder B abs_folder_path_2 = self.local_root_client_1._abspath( self.folder_path_2) log.debug('content of folder "%s"', abs_folder_path_2) for f in os.listdir(abs_folder_path_2): log.debug(f) super(TestLocalCopyPaste, self).tearDown() log.debug('*** exit TestLocalCopyPaste.tearDown() ***')
def setUp(self): """ 1. Create folder a1 in Nuxeo Drive Test Workspace sycn root 2. Create folder a2 in Nuxeo Drive Test Workspace sycn root 3. Add 10 image files in a1 4. Add 10 image files in a2 """ self.engine_1.start() self.wait_sync(wait_for_async=True) self.engine_1.stop() # Create a1 and a2 self.folder_path_1 = self.local_client_1.make_folder(u'/', u'a1') self.folder_path_2 = self.local_client_1.make_folder(u'/', u'a2') # Add image files to a1 abs_folder_path_1 = self.local_client_1._abspath(self.folder_path_1) for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1): file_name = self.FILE_NAME_PATTERN % (file_num, 'jpg') file_path = os.path.join(abs_folder_path_1, file_name) self.generate_random_jpg(file_path, random.randint(1000, 3000)) log.debug('Local test files created in a1') # Add image files to a2 abs_folder_path_2 = self.local_client_1._abspath(self.folder_path_2) for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1): file_name = self.FILE_NAME_PATTERN % (file_num, 'jpg') file_path = os.path.join(abs_folder_path_2, file_name) self.generate_random_jpg(file_path, random.randint(1000, 3000)) log.debug('Local test files created in a2') self.engine_1.start() self.wait_sync(timeout=60, wait_win=True) # Check local files in a1 self.assertTrue(self.local_client_1.exists('/a1')) children_1 = [ child.name for child in self.local_client_1.get_children_info('/a1') ] self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a1 is different from original (%d)' % (len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(children_1), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check local files in a2 self.assertTrue(self.local_client_1.exists('/a2')) children_2 = [ child.name for child in self.local_client_1.get_children_info('/a2') ] self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a2 is different from original (%d)' % (len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(children_2), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check remote files in a1 a1_remote_id = self.local_client_1.get_remote_id('/a1') self.assertIsNotNone(a1_remote_id) log.debug("Remote ref of a1: %s", a1_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id)) remote_children_1 = [ child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id) ] self.assertEqual( len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a1 is different from original (%d)' % (len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(remote_children_1), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check remote files in a2 a2_remote_id = self.local_client_1.get_remote_id('/a2') self.assertIsNotNone(a2_remote_id) log.debug("Remote ref of a2: %s", a2_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a2_remote_id)) remote_children_2 = [ child.name for child in self.remote_file_system_client_1.get_children_info(a2_remote_id) ] self.assertEqual( len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a2 is different from original (%d)' % (len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(remote_children_2), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ]))
def _local_copy_paste_files(self, stopped=False): log.debug( '*** enter TestLocalCopyPaste.test_local_copy_paste_files() ***') if not stopped: self.engine_1.start() # copy all children (files) of A to B src = self.local_root_client_1._abspath(self.folder_path_1) dst = self.local_root_client_1._abspath(self.folder_path_2) for f in os.listdir(src): shutil.copy(os.path.join(src, f), dst) if stopped: self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug('*** engine1 synced ***') # expect local 'Nuxeo Drive Test Workspace/A' to contain all the files abs_folder_path_1 = self.local_root_client_1._abspath( self.folder_path_1) self.assertTrue(os.path.exists(abs_folder_path_1)) children_1 = os.listdir(abs_folder_path_1) postcondition1 = len(children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition1_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_1), self.folder_path_1, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_expected = set(self.local_files_list) local_files_actual = set(children_1) postcondition2 = local_files_actual == local_files_expected postcondition2_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_1 if not postcondition2: unexpected_actual_files = '\n'.join( local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(local_files_actual)) postcondition2_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % ( unexpected_actual_files, missing_expected_files) # expect local 'Nuxeo Drive Test Workspace/B' to contain also the same files abs_folder_path_2 = self.local_root_client_1._abspath( self.folder_path_2) self.assertTrue(os.path.exists(abs_folder_path_2)) children_2 = os.listdir(abs_folder_path_2) postcondition3 = len(children_2) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition3_error = 'number of local files (%d) in "%s" is different from original (%d)' % \ (len(children_2), self.folder_path_2, self.NUMBER_OF_LOCAL_FILES_TOTAL) local_files_actual = set(children_2) postcondition4 = local_files_actual == local_files_expected postcondition4_error = 'file names in "%s" are different, e.g. duplicate files (renamed)' % self.folder_path_2 if not postcondition4: unexpected_actual_files = '\n'.join( local_files_actual.difference(local_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(local_files_actual)) postcondition4_error += '\nunexpected files:\n%s\n\nmissing files:\n%s' % ( unexpected_actual_files, missing_expected_files) # expect remote 'Nuxeo Drive Test Workspace/A' to contain all the files # just compare the names remote_ref_1_name = self.remote_file_system_client_1.get_info( self.remote_ref_1).name remote_children_1 = [ remote_info.name for remote_info in self. remote_file_system_client_1.get_children_info(self.remote_ref_1) ] postcondition5 = len( remote_children_1) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition5_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_1), remote_ref_1_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_1) postcondition6 = remote_files_actual == remote_files_expected postcondition6_error = ( 'remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_1_name) if not postcondition6: unexpected_actual_files = '\n'.join( local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(remote_files_actual)) postcondition6_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % ( unexpected_actual_files, missing_expected_files) # expect remote 'Nuxeo Drive Test Workspace/B' to contain all the files # just compare the names remote_ref_2_name = self.remote_file_system_client_1.get_info( self.remote_ref_2).name remote_children_2 = [ remote_info.name for remote_info in self. remote_file_system_client_1.get_children_info(self.remote_ref_2) ] postcondition7 = len( remote_children_2) == self.NUMBER_OF_LOCAL_FILES_TOTAL postcondition7_error = 'number of remote files (%d) in "%s" is different from original (%d)' % \ (len(remote_children_2), remote_ref_2_name, self.NUMBER_OF_LOCAL_FILES_TOTAL) remote_files_expected = set(self.local_files_list) remote_files_actual = set(remote_children_2) postcondition8 = remote_files_actual == remote_files_expected postcondition8_error = ( 'remote file names in "%s" are different, e.g. duplicate files (renamed)' % remote_ref_2_name) if not postcondition8: unexpected_actual_files = '\n'.join( local_files_actual.difference(remote_files_expected)) missing_expected_files = '\n'.join( local_files_expected.difference(remote_files_actual)) postcondition6_error += '\nunexpected files:\n%s\n\nmissing files\n%s' % ( unexpected_actual_files, missing_expected_files) # output the results before asserting if not postcondition1: log.debug(postcondition1_error) if not postcondition2: log.debug(postcondition2_error) if not postcondition3: log.debug(postcondition3_error) if not postcondition4: log.debug(postcondition4_error) if not postcondition5: log.debug(postcondition5_error) if not postcondition6: log.debug(postcondition6_error) if not postcondition7: log.debug(postcondition7_error) if not postcondition8: log.debug(postcondition8_error) self.assertTrue(postcondition1, postcondition1_error) self.assertTrue(postcondition2, postcondition2_error) self.assertTrue(postcondition3, postcondition3_error) self.assertTrue(postcondition4, postcondition4_error) self.assertTrue(postcondition5, postcondition5_error) self.assertTrue(postcondition6, postcondition6_error) self.assertTrue(postcondition7, postcondition7_error) self.assertTrue(postcondition8, postcondition8_error) log.debug( '*** exit TestLocalCopyPaste.test_local_copy_paste_files() ***')
def test_move_and_copy_paste_folder(self): raise SkipTest( "Disable for beta release, need to create similar test with less weird case to check simpler behavior" ) """ Move folder 'My Docs/a1' under 'My Docs/a2'. Then copy 'My Docs/a2/a1' back under 'My Docs', so files are both in 'My Docs/a1' and 'My Docs/a2/a1'. """ log.debug("*** enter CSPII7977TestCase.test_move_and_copy_paste_folder()") # move 'a1' under 'a2' src = self.local_client_1._abspath(self.folder_path_1) dst = self.local_client_1._abspath(self.folder_path_2) log.debug("*** shutil move") shutil.move(src, dst) # check that 'My Docs/a1' does not exist anymore self.assertFalse(self.local_client_1.exists(self.folder_path_1)) # check that 'My Docs/a2/a1' now exists self.assertTrue(self.local_client_1.exists(os.path.join(self.folder_path_2, "a1"))) log.debug("*** shutil copy") # copy the 'My Docs/a2/a1' tree back under 'My Docs' shutil.copytree( self.local_client_1._abspath(os.path.join(self.folder_path_2, "a1")), self.local_client_1._abspath(self.folder_path_1), ) self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug("*** engine 1 synced") if self.queue_manager_1.get_errors_count() > 0: self.queue_manager_1.requeue_errors() # Sleep error timer from time import sleep log.debug("*** force blacklisted items") sleep(2) self.wait_sync(timeout=self.SYNC_TIMEOUT) # expect '/a2/a1' to contain the files self.assertTrue(os.path.exists(self.local_client_1._abspath(os.path.join(self.folder_path_2, "a1")))) children_1 = os.listdir(self.local_client_1._abspath(os.path.join(self.folder_path_2, "a1"))) self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d) in "%s" is different from original (%d)' % (len(children_1), os.path.join(self.folder_path_2, "a1"), self.NUMBER_OF_LOCAL_FILES), ) self.assertEqual( set(children_1), set(["local%04d.txt" % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), "file names are different", ) # expect 'My Docs/a1' to contain also the files self.assertTrue(os.path.exists(self.local_client_1._abspath(self.folder_path_1))) children_2 = os.listdir(self.local_client_1._abspath(self.folder_path_1)) self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of local files (%d)in "%s" is different from original (%d)' % (len(children_2), self.folder_path_1, self.NUMBER_OF_LOCAL_FILES), ) self.assertEqual( set(children_2), set(["local%04d.txt" % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), "file names are different", ) # verify the remote one a1copy_uid = self.local_client_1.get_remote_id("/a1") a1_uid = self.local_client_1.get_remote_id("/a2/a1") try: log.debug("/a2/a1 and /a1: %s/%s", a1_uid, a1copy_uid) children_1 = self.remote_file_system_client_1.get_children_info(a1_uid) children_2 = self.remote_file_system_client_1.get_children_info(a1copy_uid) log.debug("Children1: %r", children_1) log.debug("Children2: %r", children_2) except: pass self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_1), os.path.join(self.folder_path_2, "a1"), self.NUMBER_OF_LOCAL_FILES), ) children_1_name = set() for child in children_1: children_1_name.add(child.name) self.assertEqual( set(children_1_name), set(["local%04d.txt" % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), "file names are different", ) self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_FILES, 'number of remote files (%d) in "%s" is different from original (%d)' % (len(children_2), os.path.join(self.folder_path_2, "a1"), self.NUMBER_OF_LOCAL_FILES), ) children_2_name = set() for child in children_2: children_2_name.add(child.name) self.assertEqual( set(children_2_name), set(["local%04d.txt" % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1)]), "file names are different", ) log.debug("*** exit CSPII7977TestCase.test_move_and_copy_paste_folder()")
def setUp(self): super(MultipleFilesTestCase, self).setUp() log.debug("*** enter CSPII7977TestCase.setUp()") log.debug("*** engine1 starting") self.engine_1.start() self.wait_sync() log.debug("*** engine 1 synced") log.debug("full local root path %s", self.local_client_1.get_info("/")) # create folder a1 self.local_client_1.make_folder("/", ur"a1") self.folder_path_1 = os.path.join("/", "a1") # add 100 files in folder 'My Docs/a1' for file_num in range(1, self.NUMBER_OF_LOCAL_FILES + 1): self.local_client_1.make_file(self.folder_path_1, "local%04d.txt" % file_num, self.FILE_CONTENT) log.debug("local test files created") # create folder a2 self.local_client_1.make_folder("/", ur"a2") self.folder_path_2 = os.path.join("/", "a2") self.wait_sync(timeout=self.SYNC_TIMEOUT) log.debug("*** exit CSPII7977TestCase.setUp()")
def setUp(self): super(TestLocalCopyPaste, self).setUp() log.debug('*** enter TestLocalCopyPaste.setUp() ***') log.debug('*** engine1 starting ***') self.engine_1.start() self.wait_sync(wait_for_async=True) self.engine_1.stop() log.debug('*** engine1 synced ***') log.debug("full local root path %s", self.local_root_client_1.get_info("/")) self.assertTrue(self.local_root_client_1.exists('/Nuxeo Drive Test Workspace'), "Nuxeo Drive Test Workspace should be sync") # create folder A self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_1) self.folder_path_1 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_1) # create folder B # NXDRIVE-477 If created after files are created inside A, creation of B isn't detected wy Watchdog! # Reproducible with watchdemo, need to investigate. # That's why we are now using local scan for setUp. self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_2) self.folder_path_2 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_2) # add text files in folder 'Nuxeo Drive Test Workspace/A' self.local_files_list = [] for file_num in range(1, self.NUMBER_OF_LOCAL_TEXT_FILES + 1): filename = self.FILE_NAME_PATTERN % (file_num, '.txt') self.local_root_client_1.make_file(self.folder_path_1, filename, FILE_CONTENT) self.local_files_list.append(filename) test_resources_path = self._get_test_resources_path() if test_resources_path is None: test_resources_path = 'tests/resources' self.test_doc_path = os.path.join(test_resources_path, TestLocalCopyPaste.TEST_DOC_RESOURCE) # add image files in folder 'Nuxeo Drive Test Workspace/A' abs_folder_path_1 = self.local_root_client_1._abspath(self.folder_path_1) for file_num in range(self.NUMBER_OF_LOCAL_TEXT_FILES + 1, self.NUMBER_OF_LOCAL_FILES_TOTAL + 1): filename = self.FILE_NAME_PATTERN % (file_num, os.path.splitext(self.TEST_DOC_RESOURCE)[1]) dst_path = os.path.join(abs_folder_path_1, filename) shutil.copyfile(self.test_doc_path, dst_path) self.local_files_list.append(filename) log.debug('local test files created in Nuxeo Drive Test Workspace/A') self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) self.engine_1.stop() # get remote folders reference ids self.remote_ref_1 = self.local_root_client_1.get_remote_id(self.folder_path_1) self.assertIsNotNone(self.remote_ref_1) self.remote_ref_2 = self.local_root_client_1.get_remote_id(self.folder_path_2) self.assertIsNotNone(self.remote_ref_2) self.assertTrue(self.remote_file_system_client_1.exists(self.remote_ref_1), 'remote folder for %s does not exist' % self.folder_path_1) self.assertTrue(self.remote_file_system_client_1.exists(self.remote_ref_2), 'remote folder for %s does not exist' % self.folder_path_2) self.assertEquals(len(self.remote_file_system_client_1.get_children_info(self.remote_ref_1)), self.NUMBER_OF_LOCAL_FILES_TOTAL) log.debug('*** exit TestLocalCopyPaste.setUp() ***')
def tearDown(self): log.debug('*** enter TestLocalCopyPaste.tearDown() ***') # list content of folder A abs_folder_path_1 = self.local_root_client_1._abspath(self.folder_path_1) log.debug('content of folder "%s"', abs_folder_path_1) for f in os.listdir(abs_folder_path_1): log.debug(f) # list content of folder B abs_folder_path_2 = self.local_root_client_1._abspath(self.folder_path_2) log.debug('content of folder "%s"', abs_folder_path_2) for f in os.listdir(abs_folder_path_2): log.debug(f) super(TestLocalCopyPaste, self).tearDown() log.debug('*** exit TestLocalCopyPaste.tearDown() ***')
def tearDown(self): log.debug('*** enter TestLocalPaste.tearDown()') # delete temp folder shutil.rmtree(self.local_temp) super(TestLocalPaste, self).tearDown() log.debug('*** exit TestLocalPaste.tearDown()')
def test_looping(self): # Push several items with a delay of 1s queue = BlacklistQueue(delay=1) queue.push(1, "Item1") queue.push(2, "Item2") queue.push(3, "Item3") queue.push(4, "Item4") queue.push(5, "Item5") queue.push(6, "Item6") queue.push(7, "Item7") log.debug('queue:\n%s', str(queue)) count = 0 for item in queue.process_items(): if item: log.debug('item: %s', item.get_id()) count += 1 self.assertEqual(queue.size(), 7, "queue size has changed") self.assertEqual(count, 0, "no item should have been ready for processing") sleep_time = 3 sleep(sleep_time) for item in queue.process_items(): if item: log.debug('item: %s', item.get_id()) count += 1 queue.repush(item) self.assertEqual(queue.size(), 7, "queue size has changed") self.assertEqual(count, 7, "all items should have been ready for processing") log.debug('queue:\n%s', str(queue)) count = 0 for item in queue.process_items(): if item: log.debug('item: %s', item.get_id()) count += 1 self.assertEqual(queue.size(), 7, "queue size has changed") self.assertEqual(count, 0, "no item should have been ready for processing after repush") sleep_time = 4 sleep(sleep_time) log.debug('queue:\n%s', str(queue)) count = 0 for item in queue.process_items(): if item: log.debug('item: %s', item.get_id()) count += 1 self.assertTrue(queue.is_empty(), 'queue is not empty') self.assertEqual(count, 7, "all items should have been ready for processing after repush")
def test_local_share_move_folder_with_files(self): global wait_for_security_update admin_remote_client = self.root_remote_client global src src = self.local_client_1._abspath(self.folder_path_1) global dst dst = self.local_client_1._abspath(self.folder_path_2) wait_for_security_update = True op_input = self.local_client_1.get_remote_id('/a1').split('#')[-1] admin_remote_client.execute("Document.AddPermission", url = admin_remote_client.rest_api_url + 'automation/Document.AddPermission', op_input=op_input, username=self.user_2, permission="Everything", grant="true") self.wait_sync(enforce_errors=True) wait_for_security_update = False # Sync after move operation self.wait_sync(enforce_errors=True) # Check that a1 doesn't exist anymore locally self.assertFalse(self.local_client_1.exists('/a1')) # Check local files in a2/a1 self.assertTrue(self.local_client_1.exists('/a2/a1')) children_1 = [child.name for child in self.local_client_1.get_children_info('/a2/a1')] self.assertEqual(len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a1 is different from original (%d)' % (len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # Check that a1 doesn't exist anymore remotely self.assertEqual(len(self.remote_document_client_1.get_children_info(self.workspace)), 1) # Check remote files in a2/a1 a1_remote_id = self.local_client_1.get_remote_id('/a2/a1') self.assertIsNotNone(a1_remote_id) log.debug("Remote ref of a1: %s", a1_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id)) remote_children_1 = [child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id)] self.assertEqual(len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a1 is different from original (%d)' % (len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual(set(remote_children_1), set(['file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1)])) # As Admin create a folder inside a1 parent_folder_uid = admin_remote_client.make_folder(a1_remote_id.split('#')[-1], 'inside_a1') self.wait_sync(fail_if_timeout=True) # Check that a1 doesn't exist anymore locally self.assertTrue(self.local_client_1.exists('/a2/a1/inside_a1'))
def setUp(self): super(TestLocalCopyPaste, self).setUp() log.debug('*** enter TestLocalCopyPaste.setUp() ***') log.debug('*** engine1 starting ***') self.engine_1.start() self.wait_sync(wait_for_async=True) self.engine_1.stop() log.debug('*** engine1 synced ***') log.debug("full local root path %s", self.local_root_client_1.get_info("/")) self.assertTrue( self.local_root_client_1.exists('/Nuxeo Drive Test Workspace'), "Nuxeo Drive Test Workspace should be sync") # create folder A self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_1) self.folder_path_1 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_1) # create folder B # NXDRIVE-477 If created after files are created inside A, creation of B isn't detected wy Watchdog! # Reproducible with watchdemo, need to investigate. # That's why we are now using local scan for setUp. self.local_root_client_1.make_folder("/Nuxeo Drive Test Workspace", self.FOLDER_2) self.folder_path_2 = os.path.join("/Nuxeo Drive Test Workspace", self.FOLDER_2) # add text files in folder 'Nuxeo Drive Test Workspace/A' self.local_files_list = [] for file_num in range(1, self.NUMBER_OF_LOCAL_TEXT_FILES + 1): filename = self.FILE_NAME_PATTERN % (file_num, '.txt') self.local_root_client_1.make_file(self.folder_path_1, filename, FILE_CONTENT) self.local_files_list.append(filename) test_resources_path = self._get_test_resources_path() if test_resources_path is None: test_resources_path = 'tests/resources' self.test_doc_path = os.path.join(test_resources_path, TestLocalCopyPaste.TEST_DOC_RESOURCE) # add image files in folder 'Nuxeo Drive Test Workspace/A' abs_folder_path_1 = self.local_root_client_1._abspath( self.folder_path_1) for file_num in range(self.NUMBER_OF_LOCAL_TEXT_FILES + 1, self.NUMBER_OF_LOCAL_FILES_TOTAL + 1): filename = self.FILE_NAME_PATTERN % ( file_num, os.path.splitext(self.TEST_DOC_RESOURCE)[1]) dst_path = os.path.join(abs_folder_path_1, filename) shutil.copyfile(self.test_doc_path, dst_path) self.local_files_list.append(filename) log.debug('local test files created in Nuxeo Drive Test Workspace/A') self.engine_1.start() self.wait_sync(timeout=self.SYNC_TIMEOUT) self.engine_1.stop() # get remote folders reference ids self.remote_ref_1 = self.local_root_client_1.get_remote_id( self.folder_path_1) self.assertIsNotNone(self.remote_ref_1) self.remote_ref_2 = self.local_root_client_1.get_remote_id( self.folder_path_2) self.assertIsNotNone(self.remote_ref_2) self.assertTrue( self.remote_file_system_client_1.exists(self.remote_ref_1), 'remote folder for %s does not exist' % self.folder_path_1) self.assertTrue( self.remote_file_system_client_1.exists(self.remote_ref_2), 'remote folder for %s does not exist' % self.folder_path_2) self.assertEquals( len( self.remote_file_system_client_1.get_children_info( self.remote_ref_1)), self.NUMBER_OF_LOCAL_FILES_TOTAL) log.debug('*** exit TestLocalCopyPaste.setUp() ***')
def test_local_move_folder_with_files(self): src = self.local_client_1._abspath(self.folder_path_1) dst = self.local_client_1._abspath(self.folder_path_2) shutil.move(src, dst) self.wait_sync() # Check that a1 doesn't exist anymore locally self.assertFalse(self.local_client_1.exists('/a1')) # Check local files in a2 self.assertTrue(self.local_client_1.exists('/a2')) children_2 = [ child.name for child in self.local_client_1.get_children_info('/a2') if not child.folderish ] self.assertEqual( len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a2 is different from original (%d)' % (len(children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(children_2), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check local files in a2/a1 self.assertTrue(self.local_client_1.exists('/a2/a1')) children_1 = [ child.name for child in self.local_client_1.get_children_info('/a2/a1') ] self.assertEqual( len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of local files (%d) in a1 is different from original (%d)' % (len(children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(children_1), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check that a1 doesn't exist anymore remotely self.assertEqual( len(self.remote_document_client_1.get_children_info( self.workspace)), 1) # Check remote files in a2 a2_remote_id = self.local_client_1.get_remote_id('/a2') self.assertIsNotNone(a2_remote_id) log.debug("Remote ref of a2: %s", a2_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a2_remote_id)) remote_children_2 = [ child.name for child in self.remote_file_system_client_1.get_children_info(a2_remote_id) if not child.folderish ] self.assertEqual( len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a2 is different from original (%d)' % (len(remote_children_2), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(remote_children_2), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ])) # Check remote files in a2/a1 a1_remote_id = self.local_client_1.get_remote_id('/a2/a1') self.assertIsNotNone(a1_remote_id) log.debug("Remote ref of a1: %s", a1_remote_id) self.assertTrue(self.remote_file_system_client_1.exists(a1_remote_id)) remote_children_1 = [ child.name for child in self.remote_file_system_client_1.get_children_info(a1_remote_id) ] self.assertEqual( len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES, 'Number of remote files (%d) in a1 is different from original (%d)' % (len(remote_children_1), self.NUMBER_OF_LOCAL_IMAGE_FILES)) self.assertEqual( set(remote_children_1), set([ 'file%03d.jpg' % file_num for file_num in range(1, self.NUMBER_OF_LOCAL_IMAGE_FILES + 1) ]))