diff --git a/tests/test_cli.py b/tests/test_cli.py index 4cbe7daba..a5a39dce2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -219,3 +219,33 @@ def test_reset_env( "DELETE", "http://localhost:8000/environment", ) + + +@pytest.mark.handler +@patch("blueapi.service.handler.Handler") +@patch("requests.request") +def test_reset_env2( + mock_requests: Mock, + mock_handler: Mock, + handler: Handler, + client: TestClient, + runner: CliRunner, +): + # Mock the sleep function to avoid actual delays in the test + with patch("time.sleep", return_value=None): + with patch("uvicorn.run", side_effect=None): + result = runner.invoke(main, ["serve"]) + + assert result.exit_code == 0 + + mock_requests.return_value = Mock() + + # Invoke the CLI command that would trigger the environment initialization check + runner.invoke(main, ["controller", "env", "-r"]) + + # Check if the DELETE request was made correctly + assert mock_requests.call_args[0] == ( + "DELETE", + "http://localhost:8000/environment", + ) +