Skip to content

Commit 255ae1d

Browse files
committed
fix: add missing stubs so runtime test runs without app deps installed
1 parent 85574e6 commit 255ae1d

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

tests/test_runtime.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import unittest
66
from pathlib import Path
77

8-
from fastapi import APIRouter
9-
108

119
class RuntimeTest(unittest.TestCase):
1210
@classmethod
@@ -15,6 +13,46 @@ def setUpClass(cls):
1513
config.settings = types.SimpleNamespace(DB_URL="mongodb://example/test", DB_NAME="sample", HOST="127.0.0.1", DEBUG_MODE=False, PORT=8000)
1614
sys.modules["config"] = config
1715

16+
sys.modules.setdefault("uvicorn", types.ModuleType("uvicorn"))
17+
18+
pymongo = types.ModuleType("pymongo")
19+
class _AsyncMongoClient:
20+
def __init__(self, *a, **kw): self.closed = False
21+
def __getitem__(self, name): return {"db_name": name}
22+
def close(self): self.closed = True
23+
pymongo.AsyncMongoClient = _AsyncMongoClient
24+
sys.modules["pymongo"] = pymongo
25+
26+
# Minimal fastapi stub with APIRouter support
27+
fastapi_stub = types.ModuleType("fastapi")
28+
class APIRouter:
29+
def __init__(self):
30+
self._routes = []
31+
def get(self, path, **kwargs):
32+
def wrap(fn):
33+
self._routes.append(types.SimpleNamespace(path=path, endpoint=fn))
34+
return fn
35+
return wrap
36+
class FastAPI:
37+
def __init__(self, *args, **kwargs):
38+
self._routers = []
39+
self.mongodb = None
40+
self.mongodb_client = None
41+
def on_event(self, event):
42+
return lambda fn: fn
43+
def include_router(self, router, *, prefix="", **kwargs):
44+
self._routers.append((router, prefix))
45+
@property
46+
def routes(self):
47+
return [
48+
types.SimpleNamespace(path=prefix + r.path)
49+
for router, prefix in self._routers
50+
for r in router._routes
51+
]
52+
fastapi_stub.FastAPI = FastAPI
53+
fastapi_stub.APIRouter = APIRouter
54+
sys.modules["fastapi"] = fastapi_stub
55+
1856
todo_routers = types.ModuleType("apps.todo.routers")
1957
router = APIRouter()
2058
@router.get("/hello")

0 commit comments

Comments
 (0)