diff --git a/inboard/app/base/main.py b/inboard/app/base/main.py index 1cd52be..36385a4 100644 --- a/inboard/app/base/main.py +++ b/inboard/app/base/main.py @@ -24,11 +24,10 @@ async def __call__( } ) version = f"{sys.version_info.major}.{sys.version_info.minor}" - server = ( - "Uvicorn" - if os.getenv("PROCESS_MANAGER") == "uvicorn" - else "Uvicorn, Gunicorn," - ) + process_manager = os.getenv("PROCESS_MANAGER") + if process_manager not in ["gunicorn", "uvicorn"]: + raise NameError("Process manager needs to be either uvicorn or gunicorn.") + server = "Uvicorn" if process_manager == "uvicorn" else "Uvicorn, Gunicorn," message = f"Hello World, from {server} and Python {version}!" response: Dict = {"type": "http.response.body", "body": message.encode("utf-8")} await send(response) diff --git a/tests/app/test_main.py b/tests/app/test_main.py index df89ca2..18fa3b8 100644 --- a/tests/app/test_main.py +++ b/tests/app/test_main.py @@ -102,6 +102,18 @@ def test_get_asgi_uvicorn_gunicorn( assert response.status_code == 200 assert response.text == "Hello World, from Uvicorn, Gunicorn, and Python 3.8!" + def test_get_asgi_incorrect_process_manager( + self, client_asgi: TestClient, monkeypatch: MonkeyPatch + ) -> None: + """Test `GET` request to base ASGI app with incorrect `PROCESS_MANAGER`.""" + monkeypatch.setenv("PROCESS_MANAGER", "incorrect") + monkeypatch.setenv("WITH_RELOAD", "false") + assert os.getenv("PROCESS_MANAGER") == "incorrect" + assert os.getenv("WITH_RELOAD") == "false" + with pytest.raises(NameError) as e: + client_asgi.get("/") + assert str(e) == "Process manager needs to be either uvicorn or gunicorn." + def test_get_root(self, clients: List[TestClient]) -> None: """Test a `GET` request to the root endpoint.""" for client in clients: