Skip to content

Commit 7af1296

Browse files
authored
💄 Allow filtering for teams and apps (#169)
1 parent 66dbcb5 commit 7af1296

2 files changed

Lines changed: 82 additions & 2 deletions

File tree

‎src/fastapi_cloud_cli/commands/deploy.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
304304
"Select the team you want to deploy to:",
305305
tag="team",
306306
options=[Option({"name": team.name, "value": team}) for team in teams],
307+
allow_filtering=True,
307308
)
308309

309310
toolkit.print_line()
@@ -335,6 +336,7 @@ def _configure_app(toolkit: RichToolkit, path_to_deploy: Path) -> AppConfig:
335336
selected_app = toolkit.ask(
336337
"Select the app you want to deploy to:",
337338
options=[Option({"name": app.slug, "value": app}) for app in apps],
339+
allow_filtering=True,
338340
)
339341

340342
app_name = (

‎tests/test_cli_deploy.py‎

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
assets_path = Path(__file__).parent / "assets"
2525

2626

27-
def _get_random_team() -> dict[str, str]:
28-
name = "".join(random.choices(string.ascii_lowercase, k=10))
27+
def _get_random_team(name: str | None = None) -> dict[str, str]:
28+
name = name or "".join(random.choices(string.ascii_lowercase, k=10))
2929
slug = "".join(random.choices(string.ascii_lowercase, k=10))
3030
id = "".join(random.choices(string.digits, k=10))
3131

@@ -323,6 +323,42 @@ def test_shows_teams(
323323
assert team_2["name"] in result.output
324324

325325

326+
@pytest.mark.respx
327+
def test_filter_teams(
328+
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
329+
) -> None:
330+
steps = [*"al", Keys.ENTER, Keys.CTRL_C]
331+
332+
team_1 = _get_random_team(name="Alpha Team")
333+
team_2 = _get_random_team(name="Beta Team")
334+
335+
respx_mock.get("/teams/").mock(
336+
return_value=Response(
337+
200,
338+
json={"data": [team_1, team_2]},
339+
)
340+
)
341+
342+
with (
343+
changing_dir(tmp_path),
344+
patch("rich_toolkit.container.getchar") as mock_getchar,
345+
):
346+
mock_getchar.side_effect = steps
347+
348+
result = runner.invoke(app, ["deploy"])
349+
350+
assert result.exit_code == 1
351+
352+
assert "Filter: al" in result.output
353+
354+
# Truncate part of the output before "Filter: al"
355+
filer_pos = result.output.rfind("Filter: al")
356+
last_output = result.output[filer_pos:]
357+
358+
assert team_1["name"] in last_output
359+
assert team_2["name"] not in last_output
360+
361+
326362
@pytest.mark.respx
327363
def test_asks_for_app_name_after_team(
328364
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
@@ -349,6 +385,48 @@ def test_asks_for_app_name_after_team(
349385
assert "What's your app name?" in result.output
350386

351387

388+
@pytest.mark.respx
389+
def test_filter_apps(
390+
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter
391+
) -> None:
392+
steps = [Keys.ENTER, Keys.RIGHT_ARROW, Keys.ENTER, *"an", Keys.ENTER, Keys.CTRL_C]
393+
394+
team = _get_random_team()
395+
396+
respx_mock.get("/teams/").mock(
397+
return_value=Response(
398+
200,
399+
json={"data": [team]},
400+
)
401+
)
402+
403+
app_1 = _get_random_app(team_id=team["id"], slug="My App")
404+
app_2 = _get_random_app(team_id=team["id"], slug="Another App")
405+
406+
respx_mock.get("/apps/", params={"team_id": team["id"]}).mock(
407+
return_value=Response(200, json={"data": [app_1, app_2]})
408+
)
409+
410+
with (
411+
changing_dir(tmp_path),
412+
patch("rich_toolkit.container.getchar") as mock_getchar,
413+
):
414+
mock_getchar.side_effect = steps
415+
416+
result = runner.invoke(app, ["deploy"])
417+
418+
assert result.exit_code == 1
419+
420+
assert "Filter: an" in result.output
421+
422+
# Truncate part of the output before "Filter: an"
423+
filer_pos = result.output.rfind("Filter: an")
424+
last_output = result.output[filer_pos:]
425+
426+
assert app_1["slug"] not in last_output
427+
assert app_2["slug"] in last_output
428+
429+
352430
@pytest.mark.respx
353431
def test_creates_app_on_backend(
354432
logged_in_cli: None, tmp_path: Path, respx_mock: respx.MockRouter

0 commit comments

Comments
 (0)