1515
1616from fastapi_cloud_cli .cli import app
1717from fastapi_cloud_cli .config import Settings
18+ from fastapi_cloud_cli .utils .api import BuildLogError , TooManyRetriesError
1819from tests .conftest import ConfiguredApp
1920from tests .utils import Keys , build_logs_response , changing_dir
2021
@@ -771,11 +772,14 @@ def test_shows_no_apps_found_message_when_team_has_no_apps(
771772 )
772773
773774
775+ @pytest .mark .parametrize (
776+ "error" ,
777+ [BuildLogError , TooManyRetriesError , TimeoutError ],
778+ )
774779@pytest .mark .respx (base_url = settings .base_api_url )
775- def test_handles_build_log_streaming_error (
776- logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
780+ def test_shows_error_message_on_build_exception (
781+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter , error : Exception
777782) -> None :
778- """Test that BuildLogError is caught and shows dashboard link (lines 384, 387-392)."""
779783 app_data = _get_random_app ()
780784 team_data = _get_random_team ()
781785 app_id = app_data ["id" ]
@@ -802,11 +806,10 @@ def test_handles_build_log_streaming_error(
802806 return_value = Response (200 )
803807 )
804808
805- respx_mock .get (f"/deployments/{ deployment_data ['id' ]} /build-logs" ).mock (
806- return_value = Response (422 , text = "Error" )
807- )
808-
809- with changing_dir (tmp_path ):
809+ with changing_dir (tmp_path ), patch (
810+ "fastapi_cloud_cli.utils.api.APIClient.stream_build_logs" ,
811+ side_effect = error ,
812+ ):
810813 result = runner .invoke (app , ["deploy" ])
811814
812815 assert result .exit_code == 1
@@ -815,10 +818,8 @@ def test_handles_build_log_streaming_error(
815818
816819
817820@pytest .mark .respx (base_url = settings .base_api_url )
818- def test_shows_error_message_when_build_log_streaming_fails (
819- logged_in_cli : None ,
820- tmp_path : Path ,
821- respx_mock : respx .MockRouter ,
821+ def test_shows_error_message_on_build_log_http_error (
822+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
822823) -> None :
823824 app_data = _get_random_app ()
824825 team_data = _get_random_team ()
@@ -853,6 +854,7 @@ def test_shows_error_message_when_build_log_streaming_fails(
853854 with changing_dir (tmp_path ), patch ("time.sleep" ):
854855 result = runner .invoke (app , ["deploy" ])
855856
857+ assert result .exit_code == 1
856858 assert "Unable to stream build logs" in result .output
857859 assert deployment_data ["dashboard_url" ] in result .output
858860
0 commit comments