コード例 #1
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()
コード例 #2
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()
コード例 #3
0
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)
コード例 #4
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()
コード例 #5
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()
コード例 #6
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()
コード例 #7
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()
コード例 #8
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()
コード例 #9
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()
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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()
コード例 #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_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()
コード例 #16
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)
コード例 #17
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)
コード例 #18
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()
コード例 #19
0
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)