Beispiel #1
0
def get_batch(server):
    batch = server.uploads.batch()
    assert batch
    assert repr(batch)
    assert batch.uid
    assert batch.upload_idx == 0
    assert not server.uploads.get(batch.uid)

    blob = BufferBlob(data="data", name="Test.txt", mimetype="text/plain")
    assert repr(blob)
    batch.upload(blob)
    assert batch.upload_idx == 1

    blob2 = BufferBlob(data="data2", name="Test2.txt", mimetype="text/plain")
    batch.upload(blob2)
    assert batch.upload_idx == 2

    return batch
Beispiel #2
0
def test_data(tmp_path):
    blob = BufferBlob(data="data", name="Test.txt", mimetype="text/plain")
    with blob:
        assert blob.data

    file_in = tmp_path / "file_in"
    file_in.write_bytes(b"\x00" + os.urandom(1024 * 1024) + b"\x00")
    blob = FileBlob(str(file_in))
    with blob:
        assert blob.data
Beispiel #3
0
def get_batch(server):
    batch = server.uploads.batch()
    assert batch
    assert repr(batch)
    assert not server.uploads.get(batch.uid)
    blob = BufferBlob(data='data', name='Test.txt', mimetype='text/plain')
    assert repr(blob)
    batch.upload(blob)
    assert batch.uid
    return batch
Beispiel #4
0
def test_data():
    blob = BufferBlob(data='data', name='Test.txt', mimetype='text/plain')
    with blob:
        assert blob.data

    test = 'test_file'
    with open(test, 'wb') as f:
        f.write(b'\x00' + os.urandom(1024 * 1024) + b'\x00')
    try:
        blob = FileBlob(test)
        with blob:
            assert blob.data
    finally:
        os.remove(test)
Beispiel #5
0
    def __enter__(self):
        doc = Document(name=WORKSPACE_NAME,
                       type="File",
                       properties={"dc:title": "bar.txt"})
        self.doc = self.server.documents.create(doc,
                                                parent_path=WORKSPACE_ROOT)

        if self.blobs:
            # Upload several blobs for one document
            batch = self.server.uploads.batch()
            for idx in range(self.blobs):
                blob = BufferBlob(data=f"foo {idx}", name=f"foo-{idx}.txt")
                batch.upload(blob)

            path = WORKSPACE_TEST
            batch.attach(path)
        return self.doc
Beispiel #6
0
    def test_direct_edit_version(self):
        from nuxeo.models import BufferBlob

        filename = "versionedfile.txt"
        doc_id = self.remote.make_file("/",
                                       filename,
                                       content=b"Initial content.")

        self.remote.execute(
            command="Document.CreateVersion",
            input_obj=f"doc:{doc_id}",
            increment="Major",
        )
        blob = BufferBlob(data="Updated content.",
                          name=filename,
                          mimetype="text/plain")
        batch = self.remote.uploads.batch()
        batch.upload(blob)
        self.remote.execute(command="Blob.AttachOnDocument",
                            document=doc_id,
                            input_obj=batch.get(0))
        self.remote.execute(
            command="Document.CreateVersion",
            input_obj=f"doc:{doc_id}",
            increment="Major",
        )
        versions = self.remote.execute(command="Document.GetVersions",
                                       input_obj=f"doc:{doc_id}")
        entries = versions["entries"]
        assert len(entries) == 2

        version_to_edit = None
        for entry in entries:
            if entry.get("properties").get("uid:major_version") == 1:
                version_to_edit = entry

        assert version_to_edit
        doc_id = version_to_edit["uid"]

        with patch.object(self.manager_1,
                          "open_local_file",
                          new=open_local_file):
            assert not self.direct_edit._prepare_edit(self.nuxeo_url, doc_id)
            local_path = Path(f"/{doc_id}_file-content/{filename}")
            assert not self.local.exists(local_path)
Beispiel #7
0
    def __enter__(self):
        doc = Document(
            name=self.filename,
            type=self.doc_type,
            properties={"dc:title": self.filename},
        )
        self.doc = self.server.documents.create(doc,
                                                parent_path=WORKSPACE_ROOT)

        if self.blob:
            blob = BufferBlob(data=self.filename,
                              name=self.filename,
                              mimetype="text/plain")
            batch = self.server.uploads.batch()
            blob = batch.upload(blob)
            self.doc.properties["file:content"] = blob
            self.doc.save()
        return self.doc
    def __enter__(self):
        doc = Document(name=pytest.ws_python_test_name,
                       type='File',
                       properties={
                           'dc:title': 'bar.txt',
                       })
        self.doc = self.server.documents.create(
            doc, parent_path=pytest.ws_root_path)

        if self.blobs:
            # Upload several blobs for one document
            batch = self.server.uploads.batch()
            for idx in range(self.blobs):
                blob = BufferBlob(data='foo {}'.format(idx),
                                  name='foo-{}.txt'.format(idx))
                batch.upload(blob)

            path = pytest.ws_root_path + '/' + pytest.ws_python_test_name
            batch.attach(path)
        return self.doc
Beispiel #9
0
    def __enter__(self):
        doc = Document(
            name=pytest.ws_python_test_name,
            type='File',
            properties={
                'dc:title': 'bar.txt',
            }
        )
        self.doc = self.server.documents.create(
            doc, parent_path=pytest.ws_root_path)

        if self.blob:
            blob = BufferBlob(
                data='foo',
                name='foo.txt',
                mimetype='text/plain'
            )
            batch = self.server.uploads.batch()
            blob = batch.upload(blob)
            self.doc.properties['file:content'] = blob
            self.doc.save()
        return self.doc
Beispiel #10
0
def test_empty_file(chunked, server):
    batch = server.uploads.batch()
    batch.upload(BufferBlob(data="", name="Test.txt"), chunked=chunked)