| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 | import pytestfrom clean_python import ctxfrom clean_python import DoesNotExistfrom clean_python import Jsonfrom clean_python import Tenantfrom clean_python.api_client import ApiGatewayfrom clean_python.api_client import ApiProviderclass BooksGateway(ApiGateway, path="v1/books/{id}"):    pass@pytest.fixturedef provider(fastapi_example_app) -> ApiProvider:    ctx.tenant = Tenant(id=2, name="")    yield ApiProvider(fastapi_example_app + "/", lambda a, b: "token")    ctx.tenant = None@pytest.fixturedef gateway(provider) -> ApiGateway:    return BooksGateway(provider)@pytest.fixtureasync def book(gateway: ApiGateway):    return await gateway.add({"title": "fixture", "author": {"name": "foo"}})async def test_add(gateway: ApiGateway):    response = await gateway.add({"title": "test_add", "author": {"name": "foo"}})    assert isinstance(response["id"], int)    assert response["title"] == "test_add"    assert response["author"] == {"name": "foo"}    assert response["created_at"] == response["updated_at"]async def test_get(gateway: ApiGateway, book: Json):    response = await gateway.get(book["id"])    assert response == bookasync def test_remove_and_404(gateway: ApiGateway, book: Json):    assert await gateway.remove(book["id"]) is True    assert await gateway.get(book["id"]) is None    assert await gateway.remove(book["id"]) is Falseasync def test_update(gateway: ApiGateway, book: Json):    response = await gateway.update({"id": book["id"], "title": "test_update"})    assert response["id"] == book["id"]    assert response["title"] == "test_update"    assert response["author"] == {"name": "foo"}    assert response["created_at"] != response["updated_at"]async def test_update_404(gateway: ApiGateway):    with pytest.raises(DoesNotExist):        await gateway.update({"id": 123456, "title": "test_update_404"})
 |