Skip to content

Commit

Permalink
Merge pull request fastapi#35 from fastapilabs/09-17-_update_cli_to_u…
Browse files Browse the repository at this point in the history
…se_team_id_and_not_slug

♻️ Update cli to use team id and not slug
  • Loading branch information
patrick91 authored Sep 17, 2024
2 parents e272d08 + 831bcba commit 020a92f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/fastapi_cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def archive(path: Path) -> Path:


class Team(BaseModel):
id: str
slug: str
name: str

Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/fastapi_cli/utils/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class AppConfig(BaseModel):
app_id: str
team_id: str


def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:
Expand Down
28 changes: 14 additions & 14 deletions tests/test_cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
]
},
)
Expand Down Expand Up @@ -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"},
]
},
)
Expand All @@ -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"},
Expand Down Expand Up @@ -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"}
)
Expand Down Expand Up @@ -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"}
)
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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))

Expand All @@ -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"}
)
Expand Down

0 comments on commit 020a92f

Please sign in to comment.