Ejemplo n.º 1
0
    def make_file(
        self,
        parent: str,
        name: str,
        content: bytes = None,
        file_path: Path = None,
    ) -> str:
        """
        Create a document with the given *name* and *content* using the FileManager.
        If *file_path* points to a local file, it will be used instead of *content*.

        Note: if *content* is "seen" as plain text by the FileManager, the created document
              will be a Note. It this is not what you want, use make_file_with_blob().
        """
        tmp_created = file_path is None
        if not file_path:
            file_path = make_tmp_file(self.upload_tmp_dir, content)

        try:
            file_blob = FileBlob(str(file_path))
            file_blob.name = safe_filename(name)
            blob = self.uploads.batch().upload(file_blob)
            return self.file_manager_import(self.check_ref(parent), blob)
        finally:
            if tmp_created:
                file_path.unlink()
Ejemplo n.º 2
0
 def create(
     self,
     ref: str,
     doc_type: str,
     name: str = None,
     properties: Dict[str, str] = None,
 ):
     name = safe_filename(name)
     return self.execute(
         command="Document.Create",
         input_obj=f"doc:{ref}",
         type=doc_type,
         name=name,
         properties=properties,
     )
Ejemplo n.º 3
0
 def create(
     self,
     ref: str,
     doc_type: str,
     name: str = None,
     properties: Dict[str, str] = None,
 ):
     """
     Create a document of type *doc_type*.
     The operation will not use the FileManager.
     """
     name = safe_filename(name)
     return self.execute(
         command="Document.Create",
         input_obj=f"doc:{ref}",
         type=doc_type,
         name=name,
         properties=properties,
     )
    def test_rename_duplicates(self):
        remote = self.remote_document_client_1
        local = self.local_1
        engine = self.engine_1

        # Create 7 files with the same name
        name = "Congés 2016 / 2017.txt"
        name_expected = safe_filename(name)
        for _ in range(7):
            remote.make_file("/", name, content=b"42")

        # Start sync
        engine.start()
        self.wait_sync(wait_for_async=True)

        # Check that one file exists, and engine has 6 errors
        assert local.exists(f"/{name_expected}")
        assert len(local.get_children_info("/")) == 1
        assert len(engine.dao.get_errors(limit=0)) == 6

        # Rename all remote documents with unique names
        ref = local.get_remote_id("/")
        children = self.remote_1.get_fs_children(ref)
        assert len(children) == 7
        remote_files = set()
        for child in children:
            new_name = f"{child.uid.split('#')[-1]}-{safe_filename(child.name)}"
            remote_files.add(new_name)
            remote.execute(command="NuxeoDrive.Rename",
                           id=child.uid,
                           name=new_name)

        self.wait_sync(wait_for_async=True)

        children = self.remote_1.get_fs_children(ref)
        assert len(children) == 7
        # Check that the 7 files exist locally and that there are no errors
        local_children = local.get_children_info("/")
        assert len(local_children) == 7
        local_files = {child.name for child in local_children}
        assert not engine.dao.get_errors(limit=0)
        assert remote_files == local_files