Skip to content

Commit 16859d0

Browse files
authored
✨ Show dashboard URL when app is deployed (#55)
1 parent 3227d75 commit 16859d0

2 files changed

Lines changed: 74 additions & 3 deletions

File tree

src/fastapi_cloud_cli/commands/deploy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,13 @@ def _wait_for_deployment(
336336
progress.log(
337337
f"🐔 Ready the chicken! Your app is ready at [link={deployment.url}]{deployment.url}[/link]"
338338
)
339+
340+
progress.log("")
341+
342+
progress.log(
343+
"You can also check the app logs at [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
344+
)
345+
339346
break
340347

341348
if data.get("type") == "failed":

tests/test_cli_deploy.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)