コード例 #1
0
ファイル: test_engine.py プロジェクト: nnmalpere/nuxeo-drive
    def doc_pair(name: str, synced: bool = True, with_rpaths: bool = False) -> Path:
        """Create a valid doc pair in the database and return the local_path field."""
        # Craft the local file
        finfo = FileInfo(Path("."), Path(name), False, datetime.now())
        dao.insert_local_state(finfo, Path(name).parent)
        local_path = Path(f"/{name}")

        if synced:
            # Edit pair states to mimic a synced document
            doc_pair = dao.get_state_from_local(local_path)
            assert doc_pair is not None
            assert doc_pair.local_name == name
            doc_pair.local_state = "synchronized"
            doc_pair.remote_state = "synchronized"
            dao.update_local_state(doc_pair, finfo)

            if with_rpaths:
                # Also set fake remote paths
                rinfo = RemoteFileInfo.from_dict(
                    {
                        "id": "self-uid",
                        "parentId": "parent-uid",
                        "path": "/some/path",
                        "name": name,
                        "digest": "0" * 32,
                    }
                )
                doc_pair.remote_parent_path = "remote-aprent-path"
                dao.update_remote_state(doc_pair, rinfo)

        return local_path
コード例 #2
0
    def make_file(self, parent_id: str, name: str,
                  content: bytes) -> RemoteFileInfo:
        """Create a document with the given name and content

        Creates a temporary file from the content then streams it.
        """
        file_path = make_tmp_file(self.upload_tmp_dir, content)
        try:
            fs_item = self.upload(
                file_path,
                filename=name,
                command="NuxeoDrive.CreateFile",
                parentId=parent_id,
            )
            return RemoteFileInfo.from_dict(fs_item)
        finally:
            os.remove(file_path)
コード例 #3
0
 def make_file(
     self, parent_id: str, name: str, content: bytes = None
 ) -> RemoteFileInfo:
     """
     Create a document with the given name and content.
     if content is None, creates a temporary file from the content then streams it.
     """
     if content is not None:
         file_path = make_tmp_file(self.upload_tmp_dir, content)
     else:
         file_path = name
     try:
         fs_item = self.upload(
             file_path, "NuxeoDrive.CreateFile", filename=name, parentId=parent_id
         )
         return RemoteFileInfo.from_dict(fs_item)
     finally:
         if content is not None:
             file_path.unlink()
コード例 #4
0
    def update_content(self,
                       ref: str,
                       content: bytes,
                       filename: str = None) -> RemoteFileInfo:
        """Update a document with the given content

        Creates a temporary file from the content then streams it.
        """
        file_path = make_tmp_file(self.upload_tmp_dir, content)
        try:
            if filename is None:
                filename = self.get_fs_info(ref).name
            fs_item = self.upload(
                file_path,
                command="NuxeoDrive.UpdateFile",
                filename=filename,
                id=ref,
            )
            return RemoteFileInfo.from_dict(fs_item)
        finally:
            file_path.unlink()
コード例 #5
0
def test_remote_doc_raise_drive_error(remote_doc_dict):
    del remote_doc_dict["id"]
    with pytest.raises(DriveError):
        RemoteFileInfo.from_dict(remote_doc_dict)
コード例 #6
0
def test_remote_doc_live_connect_standard_digest(remote_doc_dict):
    remote_doc_dict["digest"] = "0" * 64
    remote_doc_dict["digestAlgorithm"] = None
    document = RemoteFileInfo.from_dict(remote_doc_dict)
    assert document.digest == "0" * 64
    assert document.digest_algorithm == "sha256"
コード例 #7
0
def test_remote_doc_live_connect_exotic_digest(remote_doc_dict):
    remote_doc_dict["digest"] = '"MTYxMTIyODA1ODUzNA"'
    remote_doc_dict["digestAlgorithm"] = None
    document = RemoteFileInfo.from_dict(remote_doc_dict)
    assert document.digest == '"MTYxMTIyODA1ODUzNA"'
    assert not document.digest_algorithm
コード例 #8
0
def test_remote_doc_async_digest(remote_doc_dict):
    remote_doc_dict["digest"] = "0123456789-0"
    remote_doc_dict["digestAlgorithm"] = None
    document = RemoteFileInfo.from_dict(remote_doc_dict)
    assert document.digest == "0123456789-0"
    assert not document.digest_algorithm
コード例 #9
0
def test_remote_doc_digest(remote_doc_dict):
    remote_doc_dict["digestAlgorithm"] = "MD5"
    remote_doc_dict["digest"] = "fakedigest"
    document = RemoteFileInfo.from_dict(remote_doc_dict)
    assert document.digest == "fakedigest"
    assert document.digest_algorithm == "md5"
コード例 #10
0
def test_remote_doc_folder(remote_doc_dict):
    remote_doc_dict["folder"] = True
    document = RemoteFileInfo.from_dict(remote_doc_dict)
    assert document.folderish
コード例 #11
0
ファイル: test_objects.py プロジェクト: osivia/nuxeo-drive
def test_remote_doc_raise_unwnown_digest(remote_doc_dict):
    remote_doc_dict["digest"] = "fakedigest"
    with pytest.raises(UnknownDigest):
        RemoteFileInfo.from_dict(remote_doc_dict)