Change: Both JustAPP and JustAPIApp both will work
swadhinbiswas committed 2 months ago
1537f66
1 parent 731fffe
commit 1537f66
5 files changed
+29 -4
Showing 5 changed files+29-4
▼crates/justapi-py/python/justapi/__init__.py
+2-2
| @@ -47,7 +47,7 @@ except ImportError: | ||
47 | 47 | RateLimiter = None # type: ignore[assignment,misc] |
48 | 48 | RateLimitResult = None # type: ignore[assignment,misc] |
49 | 49 | from ._justapi import Database, DbPool, DbParam # type: ignore[import-untyped] |
50 | -from .app import JustAPIApp, JustAPI, Depends, Security, Mailer, adaptive_batch, APIRouter, Controller, controller, route_get, route_post, route_put, route_patch, route_delete, route_query, route_sse, route_websocket, JustAPITestClient, RequestValidationError, Session | |
50 | +from .app import JustAPIApp, JustAPI, JustAPP, Depends, Security, Mailer, adaptive_batch, APIRouter, Controller, controller, route_get, route_post, route_put, route_patch, route_delete, route_query, route_sse, route_websocket, JustAPITestClient, RequestValidationError, Session | |
51 | 51 | from .system import build_help, build_openapi, register_system_routes |
52 | 52 | from .exceptions import HTTPException, WebSocketException |
53 | 53 | from .websockets import WebSocket, WebSocketState, WebSocketDisconnect |
| @@ -312,7 +312,7 @@ def pydantic_schema(model_class) -> str: | ||
312 | 312 | |
313 | 313 | |
314 | 314 | __all__ = [ |
315 | - "__version__", "serve", "JustAPIApp", "JustAPI", "Depends", "Security", "Mailer", "Database", "DbPool", "DbParam", "Schema", "pydantic_schema", | |
315 | + "__version__", "serve", "JustAPIApp", "JustAPI", "JustAPP", "Depends", "Security", "Mailer", "Database", "DbPool", "DbParam", "Schema", "pydantic_schema", | |
316 | 316 | "JustAPITestClient", "testing", "tracing", "auth", "Jinja2Templates", "BackgroundTasks", "Scheduler", |
317 | 317 | "TokenStreamResponse", "ValidatedStreamResponse", "WebSocket", "Dag", "DagNode", "RateLimiter", "RateLimitResult", |
318 | 318 | "adaptive_batch", "APIRouter", "Controller", "controller", |
319 | 319 | |
▼crates/justapi-py/python/justapi/__init__.pyi
+2-2
| @@ -1,11 +1,11 @@ | ||
1 | 1 | from . import testing as testing, tracing as tracing, status as status |
2 | 2 | from ._justapi import Dag as Dag, DagNode as DagNode, Database as Database, RateLimitResult as RateLimitResult, RateLimiter as RateLimiter, Request as Request, TokenStreamResponse as TokenStreamResponse, WebSocket as WebSocket, serve as serve |
3 | -from .app import APIRouter as APIRouter, Controller as Controller, Depends as Depends, JustAPIApp as JustAPIApp, JustAPITestClient as JustAPITestClient, adaptive_batch as adaptive_batch, controller as controller, route_delete as route_delete, route_get as route_get, route_post as route_post, route_put as route_put, route_query as route_query, route_sse as route_sse, route_websocket as route_websocket | |
3 | +from .app import APIRouter as APIRouter, Controller as Controller, Depends as Depends, JustAPIApp as JustAPIApp, JustAPI as JustAPI, JustAPP as JustAPP, JustAPITestClient as JustAPITestClient, adaptive_batch as adaptive_batch, controller as controller, route_delete as route_delete, route_get as route_get, route_post as route_post, route_put as route_put, route_query as route_query, route_sse as route_sse, route_websocket as route_websocket | |
4 | 4 | from .background import BackgroundTasks as BackgroundTasks |
5 | 5 | from .responses import HTMLResponse as HTMLResponse, JSONResponse as JSONResponse, PlainTextResponse as PlainTextResponse, RedirectResponse as RedirectResponse, Response as Response, StreamingResponse as StreamingResponse |
6 | 6 | from .templating import Jinja2Templates as Jinja2Templates |
7 | 7 | |
8 | -__all__ = ['serve', 'JustAPIApp', 'Depends', 'Database', 'Schema', 'pydantic_schema', 'JustAPITestClient', 'testing', 'tracing', 'Jinja2Templates', 'BackgroundTasks', 'TokenStreamResponse', 'WebSocket', 'Dag', 'DagNode', 'RateLimiter', 'RateLimitResult', 'adaptive_batch', 'APIRouter', 'Controller', 'controller', 'route_get', 'route_post', 'route_put', 'route_delete', 'route_query', 'route_sse', 'route_websocket', 'Request', 'Response', 'HTMLResponse', 'PlainTextResponse', 'JSONResponse', 'RedirectResponse', 'StreamingResponse', 'status'] | |
8 | +__all__ = ['serve', 'JustAPIApp', 'JustAPI', 'JustAPP', 'Depends', 'Database', 'Schema', 'pydantic_schema', 'JustAPITestClient', 'testing', 'tracing', 'Jinja2Templates', 'BackgroundTasks', 'TokenStreamResponse', 'WebSocket', 'Dag', 'DagNode', 'RateLimiter', 'RateLimitResult', 'adaptive_batch', 'APIRouter', 'Controller', 'controller', 'route_get', 'route_post', 'route_put', 'route_delete', 'route_query', 'route_sse', 'route_websocket', 'Request', 'Response', 'HTMLResponse', 'PlainTextResponse', 'JSONResponse', 'RedirectResponse', 'StreamingResponse', 'status'] | |
9 | 9 | |
10 | 10 | class Schema: |
11 | 11 | def __init_subclass__(cls, **kwargs) -> None: ... |
12 | 12 | |
▼crates/justapi-py/python/justapi/app.py
+3-0
| @@ -2276,3 +2276,6 @@ class JustAPITestClient: | ||
2276 | 2276 | return _JustAPITestClient(inner, database=database) |
2277 | 2277 | |
2278 | 2278 | JustAPI = JustAPIApp |
2279 | + | |
2280 | +# Short alias: `JustAPP()` == `JustAPIApp()`. | |
2281 | +JustAPP = JustAPIApp | |
2279 | 2282 | |
▼crates/justapi-py/python/justapi/app.pyi
+3-0
| @@ -211,3 +211,6 @@ class _JustAPIGrpcMockServer: | ||
211 | 211 | |
212 | 212 | class JustAPITestClient: |
213 | 213 | def __new__(cls, app, database=None): ... |
214 | + | |
215 | +JustAPI = JustAPIApp | |
216 | +JustAPP = JustAPIApp | |
214 | 217 | |
▼crates/justapi-py/python/justapi/test_native.py
+19-0
| @@ -152,3 +152,22 @@ def test_sync_handler_no_spurious_404_under_load(): | ||
152 | 152 | if __name__ == "__main__": |
153 | 153 | test_native_api() |
154 | 154 | test_sync_handler_no_spurious_404_under_load() |
155 | + | |
156 | + | |
157 | +def test_justapp_alias_is_justapiapp(): | |
158 | + """JustAPP is an alias of JustAPIApp (and so is JustAPI).""" | |
159 | + from justapi import JustAPIApp, JustAPP, JustAPI | |
160 | + | |
161 | + assert JustAPP is JustAPIApp | |
162 | + assert JustAPI is JustAPIApp | |
163 | + | |
164 | + app = JustAPP() | |
165 | + | |
166 | + @app.get("/") | |
167 | + def root(): | |
168 | + return {"ok": True} | |
169 | + | |
170 | + from justapi import JustAPITestClient | |
171 | + | |
172 | + resp = JustAPITestClient(app).get("/") | |
173 | + assert resp["status"] == 200 | |
155 | 174 | |