diff --git a/src/fastapi_cli/commands/deploy.py b/src/fastapi_cli/commands/deploy.py index 64789ad..e513dd4 100644 --- a/src/fastapi_cli/commands/deploy.py +++ b/src/fastapi_cli/commands/deploy.py @@ -62,6 +62,7 @@ def archive(path: Path) -> Path: class Team(BaseModel): + id: str slug: str name: str @@ -81,11 +82,11 @@ class AppResponse(BaseModel): slug: str -def _create_app(team_slug: str, app_name: str) -> AppResponse: +def _create_app(team_id: str, app_name: str) -> AppResponse: with APIClient() as client: response = client.post( "/apps/", - json={"name": app_name, "team_slug": team_slug}, + json={"name": app_name, "team_id": team_id}, ) response.raise_for_status() @@ -207,10 +208,10 @@ def _configure_app( toolkit.print_line() - team_slug: str = toolkit.ask( + team = toolkit.ask( "Select the team you want to deploy to:", tag="team", - options=[Option({"name": team.name, "value": team.slug}) for team in teams], + options=[Option({"name": team.name, "value": team}) for team in teams], ) toolkit.print_line() @@ -225,11 +226,11 @@ def _configure_app( with toolkit.progress(title="Creating app...") as progress: with handle_http_errors(progress): - app_data = _create_app(team_slug, app_name) + app_data = _create_app(team.id, app_name) progress.log(f"App created successfully! App slug: {app_data.slug}") - app_config = AppConfig(app_id=app_data.id) + app_config = AppConfig(app_id=app_data.id, team_id=team.id) write_app_config(path_to_deploy, app_config) diff --git a/src/fastapi_cli/utils/apps.py b/src/fastapi_cli/utils/apps.py index 23c0a60..1a1ab9d 100644 --- a/src/fastapi_cli/utils/apps.py +++ b/src/fastapi_cli/utils/apps.py @@ -6,6 +6,7 @@ class AppConfig(BaseModel): app_id: str + team_id: str def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]: diff --git a/tests/test_cli_deploy.py b/tests/test_cli_deploy.py index 828a7d2..15a5ac4 100644 --- a/tests/test_cli_deploy.py +++ b/tests/test_cli_deploy.py @@ -101,8 +101,8 @@ def test_shows_teams( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, - {"name": "team2", "slug": "team2"}, + {"name": "team1", "slug": "team1", "id": "123"}, + {"name": "team2", "slug": "team2", "id": "456"}, ] }, ) @@ -130,8 +130,8 @@ def test_asks_for_app_name_after_team( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, - {"name": "team2", "slug": "team2"}, + {"name": "team1", "slug": "team1", "id": "123"}, + {"name": "team2", "slug": "team2", "id": "456"}, ] }, ) @@ -158,13 +158,13 @@ def test_creates_app_on_backend( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, + {"name": "team1", "slug": "team1", "id": "123"}, ] }, ) ) - respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock( + respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock( return_value=Response( 201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"}, @@ -192,13 +192,13 @@ def test_creates_and_uploads_deployment_then_fails( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, + {"name": "team1", "slug": "team1", "id": "123"}, ] }, ) ) - respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock( + respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock( return_value=Response( 201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"} ) @@ -271,13 +271,13 @@ def test_exists_successfully_when_deployment_is_done( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, + {"name": "team1", "slug": "team1", "id": "123"}, ] }, ) ) - respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock( + respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock( return_value=Response( 201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"} ) @@ -346,7 +346,7 @@ def test_exists_successfully_when_deployment_is_done_when_app_is_configured( config_path = tmp_path / ".fastapi" / "cloud.json" config_path.parent.mkdir(parents=True, exist_ok=True) - config_path.write_text('{"app_id": "1234"}') + config_path.write_text('{"app_id": "1234", "team_id": "123"}') respx_mock.get("/apps/1234").mock( return_value=Response(200, json={"slug": "demo", "id": "1234"}) @@ -413,7 +413,7 @@ def test_shows_error_when_app_does_not_exist( config_path = tmp_path / ".fastapi" / "cloud.json" config_path.parent.mkdir(parents=True, exist_ok=True) - config_path.write_text('{"app_id": "some-random-id"}') + config_path.write_text('{"app_id": "some-random-id", "team_id": "123"}') respx_mock.get("/apps/some-random-id").mock(return_value=Response(404)) @@ -436,13 +436,13 @@ def test_can_skip_waiting( 200, json={ "data": [ - {"name": "team1", "slug": "team1"}, + {"name": "team1", "slug": "team1", "id": "123"}, ] }, ) ) - respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock( + respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock( return_value=Response( 201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"} )