@@ -356,17 +356,51 @@ def test_handle_login_with_google_select_gcp_project(
356356 assert region == "us-east1"
357357
358358
359- def test_handle_login_with_google_express_signup (
359+ def test_handle_login_with_google_manual_project (
360360 monkeypatch : pytest .MonkeyPatch ,
361361) -> None :
362- """Handler should sign up for Express if eligible and user accepts TOS."""
362+ """Handler should allow manual project ID entry when '0' is selected."""
363+ monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
364+ monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
365+ monkeypatch .setattr (
366+ gcp_utils , "list_gcp_projects" , lambda limit : [("p1" , "Project 1" )]
367+ )
368+ prompts = iter ([0 , "manual-proj" , "us-east1" ])
369+ monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next (prompts ))
370+
371+ api_key , proj , region = cli_create ._handle_login_with_google ()
372+ assert api_key is None
373+ assert proj == "manual-proj"
374+ assert region == "us-east1"
375+
376+
377+ def test_handle_login_with_google_option_1 (
378+ monkeypatch : pytest .MonkeyPatch ,
379+ ) -> None :
380+ """User selects 1, enters project ID and region."""
381+ monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
382+ monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
383+ monkeypatch .setattr (gcp_utils , "list_gcp_projects" , lambda limit : [])
384+ prompts = iter (["1" , "test-proj" , "us-east1" ])
385+ monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next (prompts ))
386+
387+ api_key , proj , region = cli_create ._handle_login_with_google ()
388+ assert api_key is None
389+ assert proj == "test-proj"
390+ assert region == "us-east1"
391+
392+
393+ def test_handle_login_with_google_option_2 (
394+ monkeypatch : pytest .MonkeyPatch ,
395+ ) -> None :
396+ """User selects 2, goes through express sign up."""
363397 monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
364398 monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
365399 monkeypatch .setattr (gcp_utils , "list_gcp_projects" , lambda limit : [])
366400 monkeypatch .setattr (gcp_utils , "check_express_eligibility" , lambda : True )
367- confirms = iter ([ False , True ] )
368- monkeypatch . setattr ( click , "confirm " , lambda * a , ** k : next ( confirms ) )
369- monkeypatch .setattr (click , "prompt" , lambda * a , ** k : "1" )
401+ monkeypatch . setattr ( click , "confirm" , lambda * a , ** k : True )
402+ prompts = iter ([ "2 " , "1" ] )
403+ monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next ( prompts ) )
370404 monkeypatch .setattr (
371405 gcp_utils ,
372406 "sign_up_express" ,
@@ -383,6 +417,17 @@ def test_handle_login_with_google_express_signup(
383417 assert region == "us-central1"
384418
385419
420+ def test_handle_login_with_google_option_3 (
421+ monkeypatch : pytest .MonkeyPatch ,
422+ ) -> None :
423+ """User selects 3, aborts."""
424+ monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
425+ monkeypatch .setattr (gcp_utils , "list_gcp_projects" , lambda limit : [])
426+ monkeypatch .setattr (click , "prompt" , lambda * a , ** k : "3" )
427+ with pytest .raises (click .Abort ):
428+ cli_create ._handle_login_with_google ()
429+
430+
386431# prompt_str
387432def test_prompt_str_non_empty (monkeypatch : pytest .MonkeyPatch ) -> None :
388433 """_prompt_str should retry until a non-blank string is provided."""
@@ -416,42 +461,3 @@ def test_get_gcp_region_from_gcloud_fail(
416461 ),
417462 )
418463 assert cli_create ._get_gcp_region_from_gcloud () == ""
419-
420-
421- def test_handle_login_with_google_manual_project (
422- monkeypatch : pytest .MonkeyPatch ,
423- ) -> None :
424- """Handler should allow manual project ID entry when '0' is selected."""
425- monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
426- monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
427- monkeypatch .setattr (
428- gcp_utils , "list_gcp_projects" , lambda limit : [("p1" , "Project 1" )]
429- )
430- # First prompt is for project selection (0), second is for manual ID entry,
431- # third is for region selection.
432- prompts = iter ([0 , "manual-proj" , "us-east1" ])
433- monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next (prompts ))
434-
435- api_key , proj , region = cli_create ._handle_login_with_google ()
436- assert api_key is None
437- assert proj == "manual-proj"
438- assert region == "us-east1"
439-
440-
441- def test_handle_login_with_google_empty_projects_manual_entry (
442- monkeypatch : pytest .MonkeyPatch ,
443- ) -> None :
444- """Handler should allow manual entry if no projects are found and user accepts."""
445- monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
446- monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
447- monkeypatch .setattr (gcp_utils , "list_gcp_projects" , lambda limit : [])
448-
449- # User says Yes to "enter manually", then provides project ID and region
450- prompts = iter (["manual-proj" , "us-east1" ])
451- monkeypatch .setattr (click , "confirm" , lambda * a , ** k : True )
452- monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next (prompts ))
453-
454- api_key , proj , region = cli_create ._handle_login_with_google ()
455- assert api_key is None
456- assert proj == "manual-proj"
457- assert region == "us-east1"
0 commit comments