Skip to content

Commit 5e96ae4

Browse files
committed
test: Fix how serve is invoked to not accidentally set no_auth
#9 Branch: ServeNoAuthFlag-9 Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 33e34fa commit 5e96ae4

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

tests/commands/server/test_serve.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# First-Party
1919
from cforge.commands.server.serve import serve
20-
from tests.conftest import get_open_port
20+
from tests.conftest import get_open_port, invoke_typer_command
2121

2222

2323
class TestServeCommand:
@@ -26,15 +26,15 @@ class TestServeCommand:
2626
def test_serve_with_defaults(self) -> None:
2727
"""Test serve command with default parameters."""
2828
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run:
29-
serve()
29+
invoke_typer_command(serve)
3030
mock_run.assert_called_once()
3131
args, kwargs = mock_run.call_args
3232
assert "mcpgateway.main:app" in args
3333

3434
def test_serve_with_custom_host_port(self) -> None:
3535
"""Test serve command with custom host and port."""
3636
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run:
37-
serve(host="0.0.0.0", port=8080)
37+
invoke_typer_command(serve, host="0.0.0.0", port=8080)
3838
mock_run.assert_called_once()
3939
_, kwargs = mock_run.call_args
4040
assert kwargs.get("host") == "0.0.0.0"
@@ -43,15 +43,15 @@ def test_serve_with_custom_host_port(self) -> None:
4343
def test_serve_with_reload(self) -> None:
4444
"""Test serve command with reload enabled."""
4545
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run:
46-
serve(reload=True)
46+
invoke_typer_command(serve, reload=True)
4747
mock_run.assert_called_once()
4848
_, kwargs = mock_run.call_args
4949
assert kwargs.get("reload") is True
5050

5151
def test_serve_with_no_auth_sets_auth_required_false(self) -> None:
5252
"""Test serve command with --no-auth sets auth_required to False."""
5353
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run, patch("cforge.commands.server.serve.set_serve_settings") as mock_set_settings:
54-
serve(no_auth=True, headless=False)
54+
invoke_typer_command(serve, no_auth=True, headless=False)
5555
mock_run.assert_called_once()
5656
# When headless=False (default), UI and admin API are enabled (not headless = True)
5757
# When no_auth=True, auth_required should be False (not no_auth = False)
@@ -64,7 +64,7 @@ def test_serve_with_no_auth_sets_auth_required_false(self) -> None:
6464
def test_serve_without_no_auth_sets_auth_required_true(self) -> None:
6565
"""Test serve command without --no-auth sets auth_required to True."""
6666
with patch("cforge.commands.server.serve.uvicorn.run") as mock_run, patch("cforge.commands.server.serve.set_serve_settings") as mock_set_settings:
67-
serve(no_auth=False, headless=False)
67+
invoke_typer_command(serve, no_auth=False, headless=False)
6868
mock_run.assert_called_once()
6969
# When headless=False (default), UI and admin API are enabled (not headless = True)
7070
# When no_auth=False (default), auth_required should be True (not no_auth = True)
@@ -90,7 +90,7 @@ def test_serve_starts_and_responds(self, mock_settings):
9090
# thread does not block process exit.
9191
server_thread = threading.Thread(
9292
target=serve,
93-
kwargs={"host": "127.0.0.1", "port": port, "reload": False, "workers": 1, "log_level": "error"},
93+
kwargs={"host": "127.0.0.1", "port": port, "reload": False, "workers": 1, "log_level": "error", "no_auth": False},
9494
daemon=True,
9595
)
9696
server_thread.start()

0 commit comments

Comments
 (0)