@@ -377,7 +377,7 @@ def test_exits_successfully_when_deployment_is_done(
377377
378378
379379@pytest .mark .respx (base_url = settings .base_api_url )
380- def test_exists_successfully_when_deployment_is_done_when_app_is_configured (
380+ def test_exits_successfully_when_deployment_is_done_when_app_is_configured (
381381 logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
382382) -> None :
383383 app_data = _get_random_app ()
@@ -412,7 +412,8 @@ def test_exists_successfully_when_deployment_is_done_when_app_is_configured(
412412 return_value = Response (
413413 200 ,
414414 json = {
415- "message" : "Hello, world!" ,
415+ "message" : "All good!" ,
416+ "type" : "complete" ,
416417 },
417418 )
418419 )
@@ -426,7 +427,70 @@ def test_exists_successfully_when_deployment_is_done_when_app_is_configured(
426427
427428 assert result .exit_code == 0
428429
429- # TODO: show a message when the deployment is done (based on the status)
430+ # check that logs are shown
431+ assert "All good!" in result .output
432+
433+ # check that the dashboard URL is shown
434+ assert "You can also check the app logs at" in result .output
435+ assert deployment_data ["dashboard_url" ] in result .output
436+
437+ # check that the app URL is shown
438+ assert deployment_data ["url" ] in result .output
439+
440+
441+ @pytest .mark .respx (base_url = settings .base_api_url )
442+ def test_exits_with_error_when_deployment_fails_to_build (
443+ logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
444+ ) -> None :
445+ app_data = _get_random_app ()
446+ team_data = _get_random_team ()
447+ app_id = app_data ["id" ]
448+ team_id = team_data ["id" ]
449+ deployment_data = _get_random_deployment (app_id = app_id )
450+
451+ config_path = tmp_path / ".fastapicloud" / "cloud.json"
452+
453+ config_path .parent .mkdir (parents = True , exist_ok = True )
454+ config_path .write_text (f'{{"app_id": "{ app_id } ", "team_id": "{ team_id } "}}' )
455+
456+ respx_mock .get (f"/apps/{ app_id } " ).mock (return_value = Response (200 , json = app_data ))
457+
458+ respx_mock .post (f"/apps/{ app_id } /deployments/" ).mock (
459+ return_value = Response (201 , json = deployment_data )
460+ )
461+
462+ respx_mock .post (f"/deployments/{ deployment_data ['id' ]} /upload" ).mock (
463+ return_value = Response (
464+ 200 ,
465+ json = {"url" : "http://test.com" , "fields" : {"key" : "value" }},
466+ )
467+ )
468+
469+ respx_mock .post ("http://test.com" , data = {"key" : "value" }).mock (
470+ return_value = Response (200 )
471+ )
472+
473+ respx_mock .get (f"/deployments/{ deployment_data ['id' ]} /build-logs" ).mock (
474+ return_value = Response (
475+ 200 ,
476+ json = {
477+ "message" : "Build failed" ,
478+ "type" : "failed" ,
479+ },
480+ )
481+ )
482+
483+ respx_mock .post (
484+ f"/deployments/{ deployment_data ['id' ]} /upload-complete" ,
485+ ).mock (return_value = Response (200 ))
486+
487+ with changing_dir (tmp_path ):
488+ result = runner .invoke (app , ["deploy" ])
489+
490+ assert result .exit_code == 1
491+
492+ assert "Oh no! Something went wrong" in result .output
493+ assert deployment_data ["dashboard_url" ] in result .output
430494
431495
432496@pytest .mark .respx (base_url = settings .base_api_url )
0 commit comments