@@ -417,6 +417,52 @@ def test_handle_login_with_google_option_2(
417417 assert region == "us-central1"
418418
419419
420+ def test_handle_login_with_google_option_2_unset_project (
421+ monkeypatch : pytest .MonkeyPatch ,
422+ ) -> None :
423+ """User selects 2, goes through express sign up, and unsets existing gcloud project."""
424+ monkeypatch .setattr (gcp_utils , "check_adc" , lambda : True )
425+ monkeypatch .setattr (gcp_utils , "retrieve_express_project" , lambda : None )
426+ monkeypatch .setattr (gcp_utils , "list_gcp_projects" , lambda limit : [])
427+ monkeypatch .setattr (gcp_utils , "check_express_eligibility" , lambda : True )
428+
429+ confirms = iter ([True , True ])
430+ monkeypatch .setattr (click , "confirm" , lambda * a , ** k : next (confirms ))
431+
432+ prompts = iter (["2" , "1" ])
433+ monkeypatch .setattr (click , "prompt" , lambda * a , ** k : next (prompts ))
434+
435+ monkeypatch .setattr (
436+ gcp_utils ,
437+ "sign_up_express" ,
438+ lambda location = "us-central1" : {
439+ "api_key" : "new-key" ,
440+ "project_id" : "new-proj" ,
441+ "region" : location ,
442+ },
443+ )
444+
445+ monkeypatch .setattr (
446+ cli_create , "_get_gcp_project_from_gcloud" , lambda : "old-proj"
447+ )
448+
449+ called = {}
450+
451+ def fake_run (cmd , ** kwargs ):
452+ if cmd == ["gcloud" , "config" , "unset" , "project" ]:
453+ called ["unset" ] = True
454+ return subprocess .CompletedProcess (args = cmd , returncode = 0 )
455+ raise ValueError (f"Unexpected command: { cmd } " )
456+
457+ monkeypatch .setattr (subprocess , "run" , fake_run )
458+
459+ api_key , proj , region = cli_create ._handle_login_with_google ()
460+ assert api_key == "new-key"
461+ assert proj == "new-proj"
462+ assert region == "us-central1"
463+ assert called .get ("unset" ) is True
464+
465+
420466def test_handle_login_with_google_option_3 (
421467 monkeypatch : pytest .MonkeyPatch ,
422468) -> None :
0 commit comments