Example #1
0
async def test_create_docs_mixed(database: Database) -> None:
    async with database.create_docs(["foo"]) as docs:
        docs.create("baz")

    assert docs.status is not None
    assert len(docs.status) == 2

    keys = [key async for key in database.akeys()]

    assert len(keys) == 2
    assert sorted(keys) == ["baz", "foo"]
Example #2
0
async def test_create_docs_mixed(database: Database) -> None:
    async with database.create_docs(["foo"]) as bulk:
        bulk.create("baz")

    assert bulk.response is not None
    assert len(bulk.response) == 2

    keys = [key async for key in database.akeys()]

    assert len(keys) == 2
    assert sorted(keys) == ["baz", "foo"]
Example #3
0
async def test_create_docs_for_existing(filled_database: Database) -> None:
    async with filled_database.create_docs(["new", "foo"]) as bulk:
        bulk.create("baz")

    assert bulk.response is not None
    assert bulk.error is not None
    assert bulk.ok is not None

    assert len(bulk.response) == 3
    assert len(bulk.ok) == 1
    assert len(bulk.error) == 2
    assert bulk.response[1]["error"] == "conflict"
    assert bulk.response[2]["error"] == "conflict"
Example #4
0
async def test_create_docs_with_create_duplicate(database: Database) -> None:
    async with database.create_docs() as docs:
        foo = docs.create("foo")

        # DO NOT DO THIS! This is just using the private interface to test conflict handling.
        assert docs._docs is not None
        docs._docs.append(foo)

    assert docs.status is not None
    assert len(docs.status) == 2

    assert "ok" in docs.status[0]
    assert "error" in docs.status[1]
    assert docs.status[1]["error"] == "conflict"

    keys = [key async for key in database.akeys()]

    assert len(keys) == 1
    assert sorted(keys) == ["foo"]
Example #5
0
async def test_create_docs_with_create(database: Database) -> None:
    async with database.create_docs() as docs:
        docs.create("foo", data={"counter": 42})
        docs.create("baz")

        with pytest.raises(ValueError):
            docs.create("foo")

    assert docs.status is not None
    assert len(docs.status) == 2

    keys = [key async for key in database.akeys()]

    assert len(keys) == 2
    assert sorted(keys) == ["baz", "foo"]

    foo = await database["foo"]
    assert "counter" in foo
    assert foo["counter"] == 42