From 07aac768d633288d61abd85d055629cfe65800b2 Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Wed, 17 Nov 2021 00:27:44 -0800 Subject: [PATCH] change(fastapi): remove sqlite support Signed-off-by: Kevin Morris --- aurweb/asgi.py | 6 ++++++ test/test_asgi.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/aurweb/asgi.py b/aurweb/asgi.py index 16de771e..aafb00b2 100644 --- a/aurweb/asgi.py +++ b/aurweb/asgi.py @@ -48,6 +48,12 @@ async def app_startup(): "TEST_RECURSION_LIMIT", sys.getrecursionlimit())) sys.setrecursionlimit(recursion_limit) + backend = aurweb.config.get("database", "backend") + if backend not in aurweb.db.DRIVERS: + raise ValueError( + f"The configured database backend ({backend}) is unsupported. " + f"Supported backends: {str(aurweb.db.DRIVERS.keys())}") + session_secret = aurweb.config.get("fastapi", "session_secret") if not session_secret: raise Exception("[fastapi] session_secret must not be empty") diff --git a/test/test_asgi.py b/test/test_asgi.py index b8856741..fa2df5a1 100644 --- a/test/test_asgi.py +++ b/test/test_asgi.py @@ -45,3 +45,20 @@ async def test_asgi_http_exception_handler(): response = await aurweb.asgi.http_exception_handler(None, exc) assert response.body.decode() == \ f"

{exc.status_code} {phrase}

{exc.detail}

" + + +@pytest.mark.asyncio +async def test_asgi_app_unsupported_backends(): + config_get = aurweb.config.get + + # Test that the previously supported "sqlite" backend is now + # unsupported by FastAPI. + def mock_sqlite_backend(section: str, key: str): + if section == "database" and key == "backend": + return "sqlite" + return config_get(section, key) + + with mock.patch("aurweb.config.get", side_effect=mock_sqlite_backend): + expr = r"^.*\(sqlite\) is unsupported.*$" + with pytest.raises(ValueError, match=expr): + await aurweb.asgi.app_startup()