Example #1
0
async def test_docs_on_deleted(filled_database: Database) -> None:
    doc = await filled_database["foo"]
    await doc.delete()

    with pytest.raises(KeyError):
        async for doc in filled_database.docs(["foo"]):
            assert False

    async for doc in filled_database.docs(["foo"], create=True):
        assert doc.id == "foo"
        assert doc.exists is False
Example #2
0
async def test_docs_on_non_existant(database: Database) -> None:
    docs = [doc async for doc in database.docs(["foo"], create=True)]

    assert len(docs) == 1
    doc = docs[0]
    assert doc._dirty_cache is True
    assert doc.id == "foo"
Example #3
0
async def test_docs_contain_ddocs_with_param(
    filled_database_with_view: Database, ) -> None:
    keys = [
        doc.id
        async for doc in filled_database_with_view.docs(include_ddocs=True)
    ]

    assert "_design/test_ddoc" in keys
Example #4
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
Example #5
0
async def test_docs_do_not_contain_ddocs(
        filled_database_with_view: Database) -> None:
    keys = [doc.id async for doc in filled_database_with_view.docs()]

    assert "_design/test_ddoc" not in keys
Example #6
0
async def test_docs_with_no_ids(filled_database: Database) -> None:
    keys = [doc.id async for doc in filled_database.docs()]

    assert len(keys) == 4
    assert sorted(keys) == ["baz", "baz2", "foo", "foo2"]
Example #7
0
async def test_docs_with_prefix(filled_database: Database) -> None:
    keys = [doc.id async for doc in filled_database.docs(prefix="ba")]

    assert len(keys) == 2
    assert (sorted(keys)) == ["baz", "baz2"]
Example #8
0
async def test_docs_filtered(filled_database: Database) -> None:
    keys = [doc.id async for doc in filled_database.docs(["foo", "baz"])]

    assert len(keys) == 2
    assert "foo" in keys
    assert "baz" in keys
Example #9
0
async def test_docs_on_empty(database: Database) -> None:
    all_docs = [doc async for doc in database.docs([])]

    assert all_docs == []