def test_document_list_update(server):
    new_doc1 = Document(name='ws-js-tests1',
                        type='Workspace',
                        properties={
                            'dc:title': 'ws-js-tests1',
                        })
    new_doc2 = Document(name='ws-js-tests2',
                        type='Workspace',
                        properties={
                            'dc:title': 'ws-js-tests2',
                        })

    doc1 = server.documents.create(new_doc1, parent_path=pytest.ws_root_path)
    doc2 = server.documents.create(new_doc2, parent_path=pytest.ws_root_path)
    desc = 'sample description'
    res = server.operations.execute(
        command='Document.Update',
        params={'properties': {
            'dc:description': desc
        }},
        input_obj=[doc1.path, doc2.path])

    assert res['entity-type'] == 'documents'
    assert len(res['entries']) == 2
    assert res['entries'][0]['path'] == doc1.path
    assert res['entries'][0]['properties']['dc:description'] == desc
    assert res['entries'][1]['path'] == doc2.path
    assert res['entries'][1]['properties']['dc:description'] == desc
    doc1.delete()
    doc2.delete()
示例#2
0
def test_document_list_update(server):
    new_doc1 = Document(name="ws-js-tests1",
                        type="Workspace",
                        properties={"dc:title": "ws-js-tests1"})
    new_doc2 = Document(name="ws-js-tests2",
                        type="Workspace",
                        properties={"dc:title": "ws-js-tests2"})

    doc1 = server.documents.create(new_doc1, parent_path=WORKSPACE_ROOT)
    doc2 = server.documents.create(new_doc2, parent_path=WORKSPACE_ROOT)
    desc = "sample description"
    res = server.operations.execute(
        command="Document.Update",
        params={"properties": {
            "dc:description": desc
        }},
        input_obj=[doc1.path, doc2.path],
    )

    assert res["entity-type"] == "documents"
    assert len(res["entries"]) == 2
    assert res["entries"][0]["path"] == doc1.path
    assert res["entries"][0]["properties"]["dc:description"] == desc
    assert res["entries"][1]["path"] == doc2.path
    assert res["entries"][1]["properties"]["dc:description"] == desc
    doc1.delete()
    doc2.delete()
示例#3
0
    def get_top_documents(self) -> Iterator["Documents"]:
        """Fetch all documents at the root."""
        # Get the personal space
        # Use a try...except block to prevent loading error on the root,
        # else it will also show a loading error for root folder
        try:
            yield self.get_personal_space()
        except Exception:
            path = f"/default-domain/UserWorkspaces/{self.remote.user_id}"
            log.warning(f"Error while retrieving documents on {path!r}", exc_info=True)
            yield Doc(
                Document(
                    title=Translator.get("PERSONAL_SPACE"),
                    contextParameters={"permissions": []},
                )
            )

        # Get root folders
        # Use a try...except block to prevent loading error on the root,
        # else it will also show a loading error for the personal space.
        try:
            for doc in self.children(path="/"):
                if "Folderish" in doc.facets:
                    yield Doc(doc)
        except Exception:
            log.warning("Error while retrieving documents on '/'", exc_info=True)
            yield Doc(Document(title="/", contextParameters={"permissions": []}))
示例#4
0
def test_comments_with_params(server):
    """Test GET parameters that allow to retrieve partial list of comments."""
    if version_lt(server.client.server_version, "10.3"):
        pytest.skip("Nuxeo 10.3 minimum")

    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    try:
        # Create a bunch of comments for that document
        for idx in range(8):
            doc.comment(f"This is my comment n° {idx}")

        # Get maximum comments with default values
        comments = doc.comments()
        assert len(comments) == 8

        # Page 1
        comments = doc.comments(pageSize=5, currentPageIndex=0)
        assert len(comments) == 5

        # Page 2
        comments = doc.comments(pageSize=5, currentPageIndex=1)
        assert len(comments) == 3

        # Page 3
        comments = doc.comments(pageSize=5, currentPageIndex=2)
        assert len(comments) == 0
    finally:
        doc.delete()
示例#5
0
def test_create_doc_with_space_and_delete(server):
    doc = Document(
        name='my domain',
        type='Workspace',
        properties={
            'dc:title': 'My domain',
        })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    try:
        assert isinstance(doc, Document)
        server.documents.get(path=pytest.ws_root_path + '/my domain')
    finally:
        doc.delete()
示例#6
0
def test_document_comment(server):
    """Test the Document.comment() method, it is a simple helper."""
    if version_lt(server.client.server_version, "10.3"):
        pytest.skip("Nuxeo 10.3 minimum")

    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    try:
        # At first, the document has no comment
        assert not doc.comments()

        # Create a comment for that document
        doc.comment("This is my super comment")

        # There is now 1 comment
        comments = doc.comments()
        assert len(comments) == 1
        assert comments[0].text == "This is my super comment"

        # Delete the comment
        server.comments.delete(comments[0].uid)
    finally:
        doc.delete()
def test_document_move(server):
    doc = Document(
        name=pytest.ws_python_test_name,
        type='File',
        properties={
            'dc:title': 'bar.txt',
        })
    assert repr(doc)
    folder = Document(
        name='Test',
        type='Folder',
        properties={
            'dc:title': 'Test'
        })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    folder = server.documents.create(folder, parent_path=pytest.ws_root_path)
    try:
        doc.move(pytest.ws_root_path + '/Test', 'new name')
        assert doc.path == pytest.ws_root_path + '/Test/new name'
        children = server.documents.get_children(folder.uid)
        assert len(children) == 1
        assert children[0].uid == doc.uid
    finally:
        doc.delete()
        folder.delete()
    assert not server.documents.exists(path=doc.path)
示例#8
0
 def _create_workspace(self, title: str) -> Document:
     title = salt(title, prefix="")
     new_ws = Document(name=title, type="Workspace", properties={"dc:title": title})
     self.ws = self.root_remote.documents.create(new_ws, parent_path=TEST_WS_DIR)
     self.workspace = self.ws.uid
     self.workspace_title = self.ws.title
     return self.ws
    def setUp(self):
        self.group1 = salt("group1")
        self.group2 = salt("group2")
        self.parent_group = salt("parentGroup")
        self.grand_parent_group = salt("grandParentGroup")
        self.new_groups = (
            Group(groupname=self.group1, memberUsers=[self.user_1]),
            Group(groupname=self.group2, memberUsers=[self.user_1]),
            Group(groupname=self.parent_group, memberGroups=[self.group1]),
            Group(groupname=self.grand_parent_group, memberGroups=[self.parent_group]),
        )
        for group in self.new_groups:
            self.root_remote.groups.create(group)

        # Create test workspace
        workspace_name = salt("groupChangesTestWorkspace")
        self.workspace_group = self.root_remote.documents.create(
            Document(
                name=workspace_name,
                type="Workspace",
                properties={"dc:title": workspace_name},
            ),
            parent_path=env.WS_DIR,
        )
        self.workspace_path = self.workspace_group.path

        self.admin_remote = root_remote(base_folder=self.workspace_path)

        self.engine_1.start()
        self.wait_sync(wait_for_async=True)
示例#10
0
def test_create_doc_and_delete(server):
    doc = Document(
        name=pytest.ws_python_test_name,
        type='Workspace',
        properties={
            'dc:title': 'foo',
        })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    try:
        assert isinstance(doc, Document)
        assert doc.path == pytest.ws_python_tests_path
        assert doc.type == 'Workspace'
        assert doc.get('dc:title') == 'foo'
        assert server.documents.exists(path=pytest.ws_python_tests_path)
    finally:
        doc.delete()
    assert not server.documents.exists(path=pytest.ws_python_tests_path)
示例#11
0
def test_document_create(server):
    doc = Document(
        type='File',
        name='日本.txt',
        properties={'dc:title': '日本.txt',
                    'dc:description': 'ру́сский'}
    )
    doc = server.documents.create(doc, parent_path='/')
    try:
        assert doc.entity_type == 'document'
        assert doc.type == 'File'
        assert doc.title == '日本.txt'
        assert doc.get('dc:title') == doc.properties['dc:title'] == '日本.txt'
        assert doc.properties['dc:description'] == 'ру́сский'
    finally:
        doc.delete()
    assert not server.documents.exists(doc.uid)
def test_document_create(server):
    doc = Document(type='File',
                   name='日本.txt',
                   properties={
                       'dc:title': '日本.txt',
                       'dc:description': 'ру́сский'
                   })
    doc = server.documents.create(doc, parent_path='/')
    try:
        assert doc.entity_type == 'document'
        assert doc.type == 'File'
        assert doc.title == '日本.txt'
        assert doc.get('dc:title') == doc.properties['dc:title'] == '日本.txt'
        assert doc.properties['dc:description'] == 'ру́сский'
    finally:
        doc.delete()
    assert not server.documents.exists(doc.uid)
示例#13
0
 def _create_workspace(self, title: str) -> Document:
     title = salt(title, prefix="")
     new_ws = Document(
         name=title, type=env.DOCTYPE_FOLDERISH, properties={"dc:title": title}
     )
     self.ws = self.root_remote.documents.create(new_ws, parent_path=env.WS_DIR)
     self.workspace = self.ws.uid
     self.workspace_title = self.ws.title
     log.warning(f"Created workspace {self.ws}")
     return self.ws
示例#14
0
def test_document_create(server):
    doc = Document(
        type="File",
        name="日本.txt",
        properties={
            "dc:title": "日本.txt",
            "dc:description": "ру́сский"
        },
    )
    doc = server.documents.create(doc, parent_path="/")
    try:
        assert doc.entity_type == "document"
        assert doc.type == "File"
        assert doc.title == "日本.txt"
        assert doc.get("dc:title") == doc.properties["dc:title"] == "日本.txt"
        assert doc.properties["dc:description"] == "ру́сский"
    finally:
        doc.delete()
    assert not server.documents.exists(doc.uid)
示例#15
0
def test_document_get_children_with_permissions(server):
    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    try:
        # Without enrichers
        children = server.documents.get_children(path="/")
        assert len(children) == 1
        with pytest.raises(KeyError):
            assert "ReadWrite" in children[0].contextParameters["permissions"]

        # With enrichers
        children = server.documents.get_children(path="/",
                                                 enrichers=["permissions"])
        assert len(children) == 1
        assert "ReadWrite" in children[0].contextParameters["permissions"]
    finally:
        doc.delete()
    assert not server.documents.exists(path=doc.path)
示例#16
0
def test_document_move(server):
    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    assert repr(doc)
    folder = Document(name="Test",
                      type="Folder",
                      properties={"dc:title": "Test"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    folder = server.documents.create(folder, parent_path=WORKSPACE_ROOT)
    try:
        doc.move(WORKSPACE_ROOT + "/Test", "new name")
        assert doc.path == WORKSPACE_ROOT + "/Test/new name"
        children = server.documents.get_children(folder.uid)
        assert len(children) == 1
        assert children[0].uid == doc.uid
    finally:
        doc.delete()
        folder.delete()
    assert not server.documents.exists(path=doc.path)
示例#17
0
def test_document_get_children_with_with_provider(server):
    root = server.documents.get(path=WORKSPACE_ROOT)
    doc = Document(name=WORKSPACE_NAME,
                   type="Folder",
                   properties={"dc:title": "folder"})
    doc = server.documents.create(doc, parent_path=root.path)
    try:
        enrichers = ["permissions", "hasFolderishChild"]
        opts = {
            "pageProvider": "tree_children",
            "pageSize": 1,
            "queryParams": root.uid,
        }
        children = server.documents.query(opts=opts, enrichers=enrichers)
        assert len(children["entries"]) == 1
        entry = children["entries"][0]
        assert entry.contextParameters["permissions"]
        assert "hasFolderishChild" in entry.contextParameters
    finally:
        doc.delete()
示例#18
0
def test_document_trash(server):
    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    try:
        assert not doc.isTrashed
        doc.trash()
        assert doc.isTrashed
        doc.untrash()
        assert not doc.isTrashed
    finally:
        doc.delete()
示例#19
0
def test_follow_transition(server):
    doc = Document(name=WORKSPACE_NAME,
                   type="File",
                   properties={"dc:title": "bar.txt"})
    doc = server.documents.create(doc, parent_path=WORKSPACE_ROOT)
    try:
        assert doc.state == "project"
        doc.follow_transition("approve")
        assert doc.state == "approved"
        doc.follow_transition("backToProject")
        assert doc.state == "project"
    finally:
        doc.delete()
def test_document_move(server):
    doc = Document(name=pytest.ws_python_test_name,
                   type='File',
                   properties={
                       'dc:title': 'bar.txt',
                   })
    assert repr(doc)
    folder = Document(name='Test',
                      type='Folder',
                      properties={'dc:title': 'Test'})
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    folder = server.documents.create(folder, parent_path=pytest.ws_root_path)
    try:
        doc.move(pytest.ws_root_path + '/Test', 'new name')
        assert doc.path == pytest.ws_root_path + '/Test/new name'
        children = server.documents.get_children(folder.uid)
        assert len(children) == 1
        assert children[0].uid == doc.uid
    finally:
        doc.delete()
        folder.delete()
    assert not server.documents.exists(path=doc.path)
def test_document_trash(server):
    doc = Document(name=pytest.ws_python_test_name,
                   type='File',
                   properties={
                       'dc:title': 'bar.txt',
                   })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    try:
        assert not doc.isTrashed
        doc.trash()
        assert doc.isTrashed
        doc.untrash()
        assert not doc.isTrashed
    finally:
        doc.delete()
def test_follow_transition(server):
    doc = Document(name=pytest.ws_python_test_name,
                   type='File',
                   properties={
                       'dc:title': 'bar.txt',
                   })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    try:
        assert doc.state == 'project'
        doc.follow_transition('approve')
        assert doc.state == 'approved'
        doc.follow_transition('backToProject')
        assert doc.state == 'project'
    finally:
        doc.delete()
示例#23
0
def test_update_doc_and_delete(server):
    doc = Document(
        name=pytest.ws_python_test_name,
        type='Workspace',
        properties={
            'dc:title': 'foo',
        })
    doc = server.documents.create(doc, parent_path=pytest.ws_root_path)
    assert doc
    try:
        uid = doc.uid
        path = doc.path
        doc.set({'dc:title': 'bar'})
        doc.save()
        doc = server.documents.get(path=pytest.ws_python_tests_path)
        assert isinstance(doc, Document)
        assert doc.uid == uid
        assert doc.path == path
        assert doc.get('dc:title') == 'bar'
    finally:
        doc.delete()
示例#24
0
 def create_doc(self, path, name, type, properties, file_path=""):
     new_doc = Document(
         name=name, type=type,
         properties=properties)  # a dict of propertyname: value
     ws = self.nuxeo.documents.create(new_doc, parent_path=path)
     if file_path:
         blob = FileBlob(file_path)
         batch = self.nuxeo.uploads.batch()
         batch.upload(blob)
         uploaded = self.nuxeo.uploads.upload(batch, blob)
         operation = self.nuxeo.operations.new('Blob.AttachOnDocument')
         operation.params = {'document': path + "/" + name}
         operation.input_obj = uploaded
         operation.execute()
     ws.save()
     return ws
示例#25
0
def upload_file(server, filename):
    batch = server.uploads.batch()
    batch.upload(FileBlob(filename, mimetype="application/octet-stream"))
    doc = server.documents.create(
        Document(name=filename, type="File", properties={"dc:title":
                                                         filename}),
        parent_path="/default-domain/workspaces",
    )
    try:
        operation = server.operations.new("Blob.AttachOnDocument")
        operation.params = {"document": doc.path}
        operation.input_obj = batch.get(0)
        operation.execute(void_op=True)
    except Exception:
        doc.delete()
    return doc
示例#26
0
def create_workspace():
    """ Create a uniq workspace. """

    path = "tests-" + str(uuid.uuid1()).split("-")[0]
    ws = Document(name=path, type="Workspace", properties={"dc:title": path})
    workspace = nuxeo.documents.create(
        ws, parent_path="/default-domain/workspaces")

    # Enable synchronization on this workspace
    operation = nuxeo.operations.new("NuxeoDrive.SetSynchronization")
    operation.params = {"enable": True}
    operation.input_obj = workspace.path
    operation.execute()

    debug("Created workspace " + path)
    return workspace
示例#27
0
    def setUp(self):
        super().setUp()
        remote = pytest.root_remote

        # Create test workspace
        workspaces_path = "/default-domain/workspaces"
        workspace_name = "groupChangesTestWorkspace"
        self.workspace_path = workspaces_path + "/" + workspace_name

        self.workspace = remote.documents.create(
            Document(
                name=workspace_name,
                type="Workspace",
                properties={"dc:title": "Group Changes Test Workspace"},
            ),
            parent_path=workspaces_path,
        )

        # Create test groups
        group_names = self.get_group_names()
        for group in ("group1", "group2", "parentGroup", "grandParentGroup"):
            if group in group_names:
                remote.groups.delete(group)

        for group in [
                Group(groupname="group1", memberUsers=["driveuser_1"]),
                Group(groupname="group2", memberUsers=["driveuser_1"]),
                Group(groupname="parentGroup", memberGroups=["group1"]),
                Group(groupname="grandParentGroup",
                      memberGroups=["parentGroup"]),
        ]:
            remote.groups.create(group)

        group_names = self.get_group_names()
        assert "group1" in group_names
        assert "group2" in group_names
        assert "parentGroup" in group_names
        assert "grandParentGroup" in group_names

        self.admin_remote = DocRemote(
            pytest.nuxeo_url,
            pytest.user,
            "nxdrive-test-administrator-device",
            pytest.version,
            password=pytest.password,
            base_folder=self.workspace_path,
        )
示例#28
0
def create_workspace():
    """ Create a unique workspace. """

    path = f"tests-{uid()}"
    ws = Document(name=path, type="Workspace", properties={"dc:title": path})
    workspace = nuxeo.documents.create(
        ws, parent_path="/default-domain/workspaces")
    workspace.save()

    # Enable synchronization on this workspace
    operation = nuxeo.operations.new("NuxeoDrive.SetSynchronization")
    operation.params = {"enable": True}
    operation.input_obj = workspace.path
    operation.execute()

    debug("Created workspace {path}")
    return workspace
示例#29
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
示例#30
0
    def create(doc, parent):
        if random:
            doc = f"doc_{uid()}.txt"
        elif isinstance(doc, int):
            doc = f"doc_{doc}.txt"

        doc_info = Document(
            name=doc,
            type="Note",
            properties={
                "dc:title": doc,
                "note:note": f"Content {doc}"
            },
        )
        nuxeo.documents.create(
            doc_info, parent_path=f"/default-domain/workspaces/{parent}")
        debug(f"Created remote file {doc!r} in {parent!r}")
        time.sleep(0.05)
示例#31
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
示例#32
0
def main():

    # Connection
    host = 'http://localhost:8080/nuxeo/'
    auth = ('Administrator', 'Administrator')
    nuxeo = Nuxeo(host=host, auth=auth)

    # Create a workspace
    new_ws = Document(name='Tests',
                      type='Workspace',
                      properties={
                          'dc:title': 'Tests',
                      })
    workspace = nuxeo.documents.create(
        new_ws, parent_path='/default-domain/workspaces')
    print(workspace)

    # Create a document
    operation = nuxeo.operations.new('Document.Create')
    operation.params = {
        'type': 'File',
        'name': 'foo.txt',
        'properties': {
            'dc:title': 'foo.txt',
            'dc:description': 'bar'
        }
    }
    operation.input_obj = '/'
    doc = operation.execute()
    print(doc)

    # Create a proxy live
    operation = nuxeo.operations.new('Document.CreateLiveProxy')
    operation.params = {
        # NOTICE - ATTENTION
        # CREATE A WORKSPACE AS default-domain/workspaces/ws
        'Destination Path': '/default-domain/workspaces/ws',
    }
    operation.input_obj = '/{}'.format(doc['title'])
    proxy = operation.execute()
    print(proxy)

    entry = nuxeo.documents.get(uid=proxy['uid'])
    print(entry.type)
示例#33
0
def test_follow_transition(server):
    doc = Document(
        name=pytest.ws_python_test_name,
        type='File',
        properties={
            'dc:title': 'bar.txt',
        })
    doc = server.documents.create(
        doc, parent_path=pytest.ws_root_path)
    try:
        assert doc.state == 'project'
        doc.follow_transition('approve')
        assert doc.state == 'approved'
        doc.follow_transition('backToProject')
        assert doc.state == 'project'
    finally:
        doc.delete()
示例#34
0
def test_document_trash(server):
    doc = Document(
        name=pytest.ws_python_test_name,
        type='File',
        properties={
            'dc:title': 'bar.txt',
        })
    doc = server.documents.create(
        doc, parent_path=pytest.ws_root_path)
    try:
        assert not doc.isTrashed
        doc.trash()
        assert doc.isTrashed
        doc.untrash()
        assert not doc.isTrashed
    finally:
        doc.delete()