From 0a4ed680d762605007d2c4b3827e7136d0c86ab4 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Wed, 21 May 2025 10:36:25 +0200 Subject: [PATCH] Unit test for app.router --- tests/unit/app/__init__.py | 1 + tests/unit/app/test_routers.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/unit/app/__init__.py create mode 100644 tests/unit/app/test_routers.py diff --git a/tests/unit/app/__init__.py b/tests/unit/app/__init__.py new file mode 100644 index 00000000..57c0f58e --- /dev/null +++ b/tests/unit/app/__init__.py @@ -0,0 +1 @@ +"""Init of tests/unit/app.""" diff --git a/tests/unit/app/test_routers.py b/tests/unit/app/test_routers.py new file mode 100644 index 00000000..59b575c0 --- /dev/null +++ b/tests/unit/app/test_routers.py @@ -0,0 +1,32 @@ +"""Unit tests for routers.py.""" + +from app.routers import include_routers # noqa:E402 + +from app.endpoints import root, info, models, query, health, config # noqa:E402 + + +class MockFastAPI: + """Mock class for FastAPI.""" + + def __init__(self): + """Initialize mock class.""" + self.routers = [] + + def include_router(self, router, prefix=None): + """Register new router.""" + self.routers.append(router) + + +def test_include_routers(): + """Test the function include_routers.""" + app = MockFastAPI() + include_routers(app) + + # are all routers added? + assert len(app.routers) == 6 + assert root.router in app.routers + assert info.router in app.routers + assert models.router in app.routers + assert query.router in app.routers + assert health.router in app.routers + assert config.router in app.routers