2424assets_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
327363def 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
353431def test_creates_app_on_backend (
354432 logged_in_cli : None , tmp_path : Path , respx_mock : respx .MockRouter
0 commit comments