Skip to content

Commit 2c0acc8

Browse files
authored
Merge pull request #236 from manstis/LCORE-369
LCORE-369: Align service URLs with road-core
2 parents d6eb0d2 + e05b8ae commit 2c0acc8

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/app/routers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def include_routers(app: FastAPI) -> None:
2525
app.include_router(info.router, prefix="/v1")
2626
app.include_router(models.router, prefix="/v1")
2727
app.include_router(query.router, prefix="/v1")
28-
app.include_router(health.router, prefix="/v1")
28+
app.include_router(streaming_query.router, prefix="/v1")
2929
app.include_router(config.router, prefix="/v1")
3030
app.include_router(feedback.router, prefix="/v1")
31-
app.include_router(streaming_query.router, prefix="/v1")
32-
app.include_router(authorized.router, prefix="/v1")
31+
32+
# road-core does not version these endpoints
33+
app.include_router(health.router)
34+
app.include_router(authorized.router)

tests/unit/app/test_routers.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ class MockFastAPI:
2222

2323
def __init__(self) -> None:
2424
"""Initialize mock class."""
25-
self.routers: list[Any] = []
25+
self.routers: list[tuple[Any, Optional[str]]] = []
2626

2727
def include_router(self, router: Any, prefix: Optional[str] = None) -> None:
2828
"""Register new router."""
29-
self.routers.append(router)
29+
self.routers.append((router, prefix))
30+
31+
def get_routers(self) -> list[Any]:
32+
return [r[0] for r in self.routers]
33+
34+
def get_router_prefix(self, router: Any) -> Optional[str]:
35+
return list(filter(lambda r: r[0] == router, self.routers))[0][1]
3036

3137

3238
def test_include_routers() -> None:
@@ -36,12 +42,30 @@ def test_include_routers() -> None:
3642

3743
# are all routers added?
3844
assert len(app.routers) == 9
39-
assert root.router in app.routers
40-
assert info.router in app.routers
41-
assert models.router in app.routers
42-
assert query.router in app.routers
43-
assert health.router in app.routers
44-
assert config.router in app.routers
45-
assert feedback.router in app.routers
46-
assert streaming_query.router in app.routers
47-
assert authorized.router in app.routers
45+
assert root.router in app.get_routers()
46+
assert info.router in app.get_routers()
47+
assert models.router in app.get_routers()
48+
assert query.router in app.get_routers()
49+
assert streaming_query.router in app.get_routers()
50+
assert config.router in app.get_routers()
51+
assert feedback.router in app.get_routers()
52+
assert health.router in app.get_routers()
53+
assert authorized.router in app.get_routers()
54+
55+
56+
def test_check_prefixes() -> None:
57+
"""Test the router prefixes."""
58+
app = MockFastAPI()
59+
include_routers(app)
60+
61+
# are all routers added?
62+
assert len(app.routers) == 9
63+
assert app.get_router_prefix(root.router) is None
64+
assert app.get_router_prefix(info.router) == "/v1"
65+
assert app.get_router_prefix(models.router) == "/v1"
66+
assert app.get_router_prefix(query.router) == "/v1"
67+
assert app.get_router_prefix(streaming_query.router) == "/v1"
68+
assert app.get_router_prefix(config.router) == "/v1"
69+
assert app.get_router_prefix(feedback.router) == "/v1"
70+
assert app.get_router_prefix(health.router) is None
71+
assert app.get_router_prefix(authorized.router) is None

0 commit comments

Comments
 (0)