Beispiel #1
0
async def test_save_on_unfetched(doc: Document) -> None:
    await doc.save()

    new_doc = Document(doc._database, doc["_id"])

    att = new_doc.attachment("lipsum.txt")
    with pytest.raises(ValueError):
        await att.save(text, "text/plain")

    new_doc = await doc._database.get(doc["_id"])
    att = new_doc.attachment("image.webp")
    await att.save(text, "text/plain")
Beispiel #2
0
async def test_delete(doc: Document) -> None:
    await doc.save()
    att = doc.attachment("lipsum.txt")
    await att.save(text, "text/plain")

    await att.delete()

    att = doc.attachment("lipsum.txt")
    with pytest.raises(NotFoundError):
        await att.fetch()

    assert not await att.exists()
Beispiel #3
0
async def test_get_on_unfetched(doc: Document) -> None:
    await doc.save()
    await doc.attachment("image.webp").save(image, "image/webp")

    new_doc = Document(doc._database, doc["_id"])
    att = new_doc.attachment("image.webp")
    data = await att.fetch()
    assert data == image
Beispiel #4
0
async def test_get(doc: Document) -> None:
    await doc.save()
    await doc.attachment("image.webp").save(image, "image/webp")

    att = doc.attachment("image.webp")
    assert await att.exists()
    data = await att.fetch()
    assert data == image
    assert att.content_type == "image/webp"
Beispiel #5
0
async def test_update(doc: Document) -> None:
    await doc.save()

    doc["value"] = 42
    await doc.save()

    att = doc.attachment("lipsum.txt")
    await att.save(text, "text/plain")

    att = doc.attachment("image.webp")
    await att.save(image, "image/webp")

    doc["value"] = 43
    await doc.save()

    new_doc = await doc._database.get(doc["_id"])
    assert new_doc["value"] == 43
    assert await new_doc.attachment("lipsum.txt").fetch() == text
    assert await new_doc.attachment("image.webp").fetch() == image
Beispiel #6
0
async def test_conflict_on_update(doc: Document) -> None:
    await doc.save()

    outdated = await doc._database.get(doc["_id"])

    att = doc.attachment("lipsum.txt")
    await att.save(text, "text/plain")

    with pytest.raises(ConflictError):
        await outdated.attachment("image.webp").save(image, "image/webp")

    await doc.attachment("image.webp").save(image, "image/webp")
Beispiel #7
0
async def test_save_binary(doc: Document) -> None:
    await doc.save()
    att = doc.attachment("image.webp")
    await att.save(image, "image/webp")
Beispiel #8
0
async def test_save_text(doc: Document) -> None:
    await doc.save()
    att = doc.attachment("lipsum.txt")
    await att.save(text, "text/plain")