async def large_filled_database(database: Database) -> AsyncGenerator[Database, None]: async with database.update_docs( [f"doc{i}" for i in range(2000)], create=True ) as docs: async for doc in docs: doc["llama"] = "awesome" yield database
async def test_view_avalues(filled_database_with_view: Database) -> None: docs = [ doc async for doc in filled_database_with_view.view( "test_ddoc", "null_view" ).avalues() ] assert len(docs) == 4
async def test_null_view_docs_with_deleted(filled_database_with_view: Database) -> None: doc = await filled_database_with_view["baz"] await doc.delete() docs = [ doc async for doc in filled_database_with_view.view("test_ddoc", "null_view").docs( ids=["baz"] ) ] assert len(docs) == 0
async def test_null_view_docs(filled_database_with_view: Database) -> None: values = [ doc.id async for doc in filled_database_with_view.view("test_ddoc", "null_view").docs() ] assert len(values) == 4 assert values[0] == "baz" assert values[1] == "baz2" assert values[2] == "foo" assert values[3] == "foo2"
async def test_null_view_ids_with_prefix(filled_database_with_view: Database) -> None: values = [ key async for key in filled_database_with_view.view("test_ddoc", "null_view").ids( prefix="ba" ) ] assert len(values) == 2 assert values[0] == "baz" assert values[1] == "baz2"
async def test_holding_docs_wrong(filled_database_with_view: Database) -> None: with pytest.raises(ValueError): async for doc in filled_database_with_view.view("test_ddoc", "null_view").docs( ids=["baz"], prefix="foo" ): pass