Ejemplo n.º 1
0
def test_collection_user_permissions():
    client = common.login_with_test_user(common.client())

    collection_id = common.get_collection_id(client, "NER Test Collection")
    assert collection_id != None
    permissions = client.get_collection_permissions(collection_id)
    assert permissions.to_dict() == {
        "view": True,
        "annotate": True,
        "add_documents": True,
        "add_images": True,
        "modify_users": False,
        "modify_labels": False,
        "modify_document_metadata": True,
        "download_data": False,
        "archive": False,
        "delete_documents": False
    }

    collection_id = common.get_collection_id(client, "Trial Collection")
    assert collection_id != None
    permissions = client.get_collection_permissions(collection_id)
    assert permissions.to_dict() == {
        "view": True,
        "annotate": True,
        "add_documents": True,
        "add_images": True,
        "modify_users": True,
        "modify_labels": True,
        "modify_document_metadata": True,
        "download_data": True,
        "archive": True,
        "delete_documents": True
    }
Ejemplo n.º 2
0
def test_add_and_delete_documents():
    client = common.login_with_test_user(common.client())

    collection_id = common.get_collection_id(client, "Trial Collection")
    assert collection_id != None

    added_doc_id = client.add_document(collection_id=collection_id,
                                       text="This is a test document to be deleted.")
    assert added_doc_id != None
    
    added_doc_id_2 = client.add_document(collection_id=collection_id,
                                       text="This is a test document to be deleted.")
    assert added_doc_id_2 != None
    
    delete_resp = client.delete_documents([added_doc_id, added_doc_id_2])
    assert delete_resp != None
    assert isinstance(delete_resp, dict)
    
    assert delete_resp["success"]
    
    changed_objs = delete_resp["changed_objs"]
    assert len(changed_objs["annotations"]["deleted"]) == 0
    assert added_doc_id in changed_objs["documents"]["deleted"]
    assert added_doc_id_2 in changed_objs["documents"]["deleted"]
    
Ejemplo n.º 3
0
def test_delete_document_not_allowed():
    client = common.login_with_test_user(common.client())

    collection_id = common.get_collection_id(client, "Trial Collection")
    assert collection_id != None
    
    with pytest.raises(pine.client.exceptions.PineClientHttpException):
        client.delete_document("nonexistent")
Ejemplo n.º 4
0
def test_download_collection_data_errors():
    # find a collection that has annotations that the test user does NOT have access to
    user = "******"
    collection_title = "NER Test Collection"
    client = common.login_with_user(user, common.client())

    with pytest.raises(pine.client.exceptions.PineClientValueException):
        client.download_collection_data(None)

    collection_id = common.get_collection_id(client, collection_title)
    assert collection_id != None
    with pytest.raises(pine.client.exceptions.PineClientHttpException) as excinfo:
        client.download_collection_data(collection_id)
    assert excinfo.value.status_code == 401
Ejemplo n.º 5
0
def test_download_collection_data():
    # find a collection that has annotations that the test user has access to
    user = "******"
    collection_title = "NER Test Collection"
    client = common.login_with_user(user, common.client())

    col_data = common.test_collection_data(collection_title)
    assert col_data != None
    collection_id = common.get_collection_id(client, collection_title)
    assert collection_id != None

    # start with nothing but IDs
    kwargs = {
        "collection_id": collection_id,
        "include_collection_metadata": False,
        "include_document_metadata": False,
        "include_document_text": False,
        "include_annotations": False,
        "include_annotation_latest_version_only": True
    }
    data = client.download_collection_data(**kwargs)
    assert set(data.keys()) == {"_id", "documents"}
    assert len(data["documents"]) == col_data["documents"]["num_docs"]
    for doc in data["documents"]:
        assert set(doc.keys()) == {"_id"}
    doc_ids = [doc["_id"] for doc in data["documents"]]
    
    # turn on collection metadata
    kwargs["include_collection_metadata"] = True
    data = client.download_collection_data(**kwargs)
    assert set(data.keys()) == {"_id", "documents", "annotators", "viewers", "metadata",
                                "configuration", "labels", "archived", "creator_id"}
    assert len(data["documents"]) == len(doc_ids)
    for doc in data["documents"]:
        assert set(doc.keys()) == {"_id"}

    # turn on document metadata
    kwargs["include_document_metadata"] = True
    data = client.download_collection_data(**kwargs)
    assert len(data["documents"]) == len(doc_ids)
    for doc in data["documents"]:
        assert set(doc.keys()) == {"_id", "metadata", "has_annotated", "creator_id", "overlap"}

    # turn on document text
    kwargs["include_document_text"] = True
    data = client.download_collection_data(**kwargs)
    assert len(data["documents"]) == len(doc_ids)
    for doc in data["documents"]:
        assert set(doc.keys()) == {"_id", "metadata", "has_annotated", "creator_id", "overlap", "text"}

    # turn on annotations
    kwargs["include_annotations"] = True
    data = client.download_collection_data(**kwargs)
    assert len(data["documents"]) == len(doc_ids)
    for doc in data["documents"]:
        assert set(doc.keys()) == {"_id", "metadata", "has_annotated", "creator_id", "overlap", "text", "annotations"}
        annotations = doc["annotations"]
        assert type(annotations) is list and len(annotations) > 0
        for annotation in annotations:
            assert set(annotation.keys()) == {"_id", "creator_id", "annotation"}

    # turn on all annotation versions
    kwargs["include_annotation_latest_version_only"] = False
    data = client.download_collection_data(**kwargs)
    assert len(data["documents"]) == len(doc_ids)
    for doc in data["documents"]:
        annotations = doc["annotations"]
        assert type(annotations) is list and len(annotations) > 0
        for annotation in annotations:
            assert set(annotation.keys()) == {"_id", "creator_id", "annotation", "_version", "_latest_version"}