def get_client(app, router):
    config = {"identifier": "uuid", "identifier_class": UUID}
    route_builder1 = RouteBuilder(models.Pizza, config=config)
    route_builder1.add_all_routes(router)
    route_builder2 = RouteBuilder(models.Topping, config=config)
    route_builder2.add_all_routes(router)
    app.include_router(router)
    return TestClient(app)
def get_client(app, router):
    route_builder = RouteBuilder(
        SimpleModel,
        config={"identifier": "uuid", "identifier_class": UUID},
    )
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app)
Exemple #3
0
def test_route_builder_with_owner_removes_owner_field():
    router = APIRouter()
    route_builder = RouteBuilder(models.SimpleModelWithOwner, owner_field="owner", authentication=lambda: None)
    route_builder.add_all_routes(router)
    assert "title" in route_builder.new_instance_schema.schema().keys()
    assert "owner" not in route_builder.new_instance_schema.schema().keys()
    assert "title" in route_builder.instance_schema.schema().keys()
    assert "owner" not in route_builder.instance_schema.schema().keys()
def get_client(app, router):
    config = {"identifier": "uuid", "identifier_class": UUID}
    route_builder = RouteBuilder(
        UnauthenticatedModel,
        config=config,
    )
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app)
Exemple #5
0
def get_client(app, router):
    def filter_by_name(_):
        return Q(name__contains="XXX")

    route_builder = RouteBuilder(SimpleModel,
                                 request_fields=["name"],
                                 response_fields=["name"],
                                 query_filter=filter_by_name)
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app)
Exemple #6
0
def get_client(app, router):
    config = {"identifier": "uuid", "identifier_class": UUID}
    route_builder = RouteBuilder(
        SimpleModelWithOwner,
        request_fields=["name"],
        response_fields=["name", "uuid"],
        config=config,
        owner_field="owner",
        authentication=check_api_key,
    )
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app)
Exemple #7
0
def get_client(router):
    authentication = get_user_authentication()
    route_builder = RouteBuilder(
        SimpleJWTModel,
        request_fields=["name"],
        response_fields=["name", "uuid"],
        config={
            "identifier": "uuid",
            "identifier_class": UUID
        },
        authentication=authentication,
    )

    route_builder.add_all_routes(router)
    application.include_router(router)
    return TestClient(application)
Exemple #8
0
def test_route_builder_adds_routes():
    router = APIRouter()
    route_builder = RouteBuilder(models.SimpleModel)
    route_builder.add_all_routes(router)
    assert len(router.routes) == 6
    assert router.routes[0].path == "/simplemodels/"
    assert router.routes[1].path == "/simplemodels/{identifier}/"
    assert router.routes[2].path == "/simplemodels/"
    assert router.routes[3].path == "/simplemodels/{identifier}/"
    assert router.routes[4].path == "/simplemodels/{identifier}/"
    assert router.routes[5].path == "/simplemodels/{identifier}/"
    assert router.routes[0].methods == {"GET"}
    assert router.routes[1].methods == {"GET"}
    assert router.routes[2].methods == {"POST"}
    assert router.routes[3].methods == {"PUT"}
    assert router.routes[4].methods == {"PATCH"}
    assert router.routes[5].methods == {"DELETE"}
Exemple #9
0
def get_client(app, router):
    route_builder = RouteBuilder(SimpleModelWithChoices)
    route_builder.add_all_routes(router)
    app.include_router(router)

    application = FastAPI(
        title="ProjectX",
        description="ProjectX Demo",
        version="0.0.1",
        docs_url="/api/docs",
        redoc_url="/api/redoc",
        openapi_url="/api/v1/openapi.json",
    )

    application.include_router(router, prefix="/api")

    application.openapi()
    return TestClient(app), route_builder
def get_client(app, router):
    route_builder = RouteBuilder(SimpleModelWithDefaultFields)
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app), route_builder
def get_client(request, app, router):
    config = request.param["config"]
    route_builder = RouteBuilder(request.param["model"], config=config)
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app), route_builder
Exemple #12
0
def get_client(app, router):
    route_builder = RouteBuilder(ModelWithValidation)
    route_builder.add_all_routes(router)
    app.include_router(router)
    return TestClient(app), route_builder