示例#1
0
async def test_find_sorted(filled_database: Database) -> None:
    await filled_database.index({"fields": ["bar2"]})

    matching_docs = [
        doc async for doc in filled_database.find({"bar": True}, sort=["bar2"])
    ]

    assert len(matching_docs) == 3
    assert matching_docs[0]["bar2"] == 1
    assert matching_docs[1]["bar2"] == 2
    assert matching_docs[2]["bar2"] == 3
示例#2
0
async def test_many_docs(large_filled_database: Database) -> None:
    keys = [key async for key in large_filled_database.akeys()]
    assert len(keys) == 2000

    docs = [doc async for doc in large_filled_database.docs()]
    assert len(docs) == 2000

    find_docs = [
        doc async for doc in large_filled_database.find(
            selector={"llama": "awesome"})
    ]
    assert len(find_docs) == 2000
示例#3
0
async def test_find_limited(filled_database: Database) -> None:
    matching_docs = [
        doc async for doc in filled_database.find({"bar": True}, limit=1)
    ]

    assert len(matching_docs) == 1

    from aiocouch.document import Document

    matching_keys = []
    for doc in matching_docs:
        assert isinstance(doc, Document)
        matching_keys.append(doc.id)

    assert "baz2" in matching_keys
示例#4
0
async def test_find_fields_parameter_gets_rejected(database: Database) -> None:
    with pytest.raises(ValueError):
        [doc async for doc in database.find({"bar": True}, fields="anything")]