Skip to content

Commit 831bcba

Browse files
committed
♻️ Update cli to use team id and not slug
1 parent e272d08 commit 831bcba

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/fastapi_cli/commands/deploy.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def archive(path: Path) -> Path:
6262

6363

6464
class Team(BaseModel):
65+
id: str
6566
slug: str
6667
name: str
6768

@@ -81,11 +82,11 @@ class AppResponse(BaseModel):
8182
slug: str
8283

8384

84-
def _create_app(team_slug: str, app_name: str) -> AppResponse:
85+
def _create_app(team_id: str, app_name: str) -> AppResponse:
8586
with APIClient() as client:
8687
response = client.post(
8788
"/apps/",
88-
json={"name": app_name, "team_slug": team_slug},
89+
json={"name": app_name, "team_id": team_id},
8990
)
9091

9192
response.raise_for_status()
@@ -207,10 +208,10 @@ def _configure_app(
207208

208209
toolkit.print_line()
209210

210-
team_slug: str = toolkit.ask(
211+
team = toolkit.ask(
211212
"Select the team you want to deploy to:",
212213
tag="team",
213-
options=[Option({"name": team.name, "value": team.slug}) for team in teams],
214+
options=[Option({"name": team.name, "value": team}) for team in teams],
214215
)
215216

216217
toolkit.print_line()
@@ -225,11 +226,11 @@ def _configure_app(
225226

226227
with toolkit.progress(title="Creating app...") as progress:
227228
with handle_http_errors(progress):
228-
app_data = _create_app(team_slug, app_name)
229+
app_data = _create_app(team.id, app_name)
229230

230231
progress.log(f"App created successfully! App slug: {app_data.slug}")
231232

232-
app_config = AppConfig(app_id=app_data.id)
233+
app_config = AppConfig(app_id=app_data.id, team_id=team.id)
233234

234235
write_app_config(path_to_deploy, app_config)
235236

src/fastapi_cli/utils/apps.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class AppConfig(BaseModel):
88
app_id: str
9+
team_id: str
910

1011

1112
def get_app_config(path_to_deploy: Path) -> Optional[AppConfig]:

tests/test_cli_deploy.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def test_shows_teams(
101101
200,
102102
json={
103103
"data": [
104-
{"name": "team1", "slug": "team1"},
105-
{"name": "team2", "slug": "team2"},
104+
{"name": "team1", "slug": "team1", "id": "123"},
105+
{"name": "team2", "slug": "team2", "id": "456"},
106106
]
107107
},
108108
)
@@ -130,8 +130,8 @@ def test_asks_for_app_name_after_team(
130130
200,
131131
json={
132132
"data": [
133-
{"name": "team1", "slug": "team1"},
134-
{"name": "team2", "slug": "team2"},
133+
{"name": "team1", "slug": "team1", "id": "123"},
134+
{"name": "team2", "slug": "team2", "id": "456"},
135135
]
136136
},
137137
)
@@ -158,13 +158,13 @@ def test_creates_app_on_backend(
158158
200,
159159
json={
160160
"data": [
161-
{"name": "team1", "slug": "team1"},
161+
{"name": "team1", "slug": "team1", "id": "123"},
162162
]
163163
},
164164
)
165165
)
166166

167-
respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock(
167+
respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock(
168168
return_value=Response(
169169
201,
170170
json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"},
@@ -192,13 +192,13 @@ def test_creates_and_uploads_deployment_then_fails(
192192
200,
193193
json={
194194
"data": [
195-
{"name": "team1", "slug": "team1"},
195+
{"name": "team1", "slug": "team1", "id": "123"},
196196
]
197197
},
198198
)
199199
)
200200

201-
respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock(
201+
respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock(
202202
return_value=Response(
203203
201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"}
204204
)
@@ -271,13 +271,13 @@ def test_exists_successfully_when_deployment_is_done(
271271
200,
272272
json={
273273
"data": [
274-
{"name": "team1", "slug": "team1"},
274+
{"name": "team1", "slug": "team1", "id": "123"},
275275
]
276276
},
277277
)
278278
)
279279

280-
respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock(
280+
respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock(
281281
return_value=Response(
282282
201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"}
283283
)
@@ -346,7 +346,7 @@ def test_exists_successfully_when_deployment_is_done_when_app_is_configured(
346346
config_path = tmp_path / ".fastapi" / "cloud.json"
347347

348348
config_path.parent.mkdir(parents=True, exist_ok=True)
349-
config_path.write_text('{"app_id": "1234"}')
349+
config_path.write_text('{"app_id": "1234", "team_id": "123"}')
350350

351351
respx_mock.get("/apps/1234").mock(
352352
return_value=Response(200, json={"slug": "demo", "id": "1234"})
@@ -413,7 +413,7 @@ def test_shows_error_when_app_does_not_exist(
413413
config_path = tmp_path / ".fastapi" / "cloud.json"
414414

415415
config_path.parent.mkdir(parents=True, exist_ok=True)
416-
config_path.write_text('{"app_id": "some-random-id"}')
416+
config_path.write_text('{"app_id": "some-random-id", "team_id": "123"}')
417417

418418
respx_mock.get("/apps/some-random-id").mock(return_value=Response(404))
419419

@@ -436,13 +436,13 @@ def test_can_skip_waiting(
436436
200,
437437
json={
438438
"data": [
439-
{"name": "team1", "slug": "team1"},
439+
{"name": "team1", "slug": "team1", "id": "123"},
440440
]
441441
},
442442
)
443443
)
444444

445-
respx_mock.post("/apps/", json={"name": "demo", "team_slug": "team1"}).mock(
445+
respx_mock.post("/apps/", json={"name": "demo", "team_id": "123"}).mock(
446446
return_value=Response(
447447
201, json={"id": "1234", "name": "demo", "team_id": "123", "slug": "demo"}
448448
)

0 commit comments

Comments
 (0)