Spaces:
Running
Running
File size: 1,945 Bytes
ae5ef37 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
SPEC = spec_from_file_location("signalmesh_gridstack", ROOT / "signalmesh_gridstack.py")
if SPEC is None or SPEC.loader is None:
raise RuntimeError("could not load signalmesh_gridstack.py")
grid = module_from_spec(SPEC)
SPEC.loader.exec_module(grid)
class GridStackNextJsCapabilityTests(unittest.TestCase):
def test_harvests_app_router_function_and_const_handlers(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
route = root / "app" / "api" / "mesh" / "[...path]" / "route.ts"
route.parent.mkdir(parents=True)
route.write_text(
"export async function GET() { return Response.json({ ok: true }); }\n"
"export const POST = async () => Response.json({ ok: true });\n"
)
caps = grid._harvest_route_caps(root)
names = {item["name"] for item in caps}
self.assertIn("GET /api/mesh/[...path]", names)
self.assertIn("POST /api/mesh/[...path]", names)
def test_route_groups_do_not_change_public_path_and_reexports_are_found(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
route = root / "src" / "app" / "(admin)" / "api" / "operator" / "[id]" / "route.ts"
route.parent.mkdir(parents=True)
route.write_text(
"const handler = async () => new Response();\n"
"export { handler as PATCH, handler as DELETE };\n"
)
caps = grid._harvest_route_caps(root)
names = {item["name"] for item in caps}
self.assertIn("DELETE /api/operator/[id]", names)
self.assertIn("PATCH /api/operator/[id]", names)
if __name__ == "__main__":
unittest.main()
|