@@ -2600,6 +2600,71 @@ def test_client_options_universe_configured_with_api_override(self):
2600
2600
2601
2601
assert tasks ._baseUrl == fake_api_endpoint
2602
2602
2603
+ def test_universe_env_var_configured_empty (self ):
2604
+ credentials = mock .Mock (spec = google .auth .credentials .Credentials )
2605
+ discovery = read_datafile ("tasks.json" )
2606
+
2607
+ with self .assertRaises (universe .EmptyUniverseError ):
2608
+ with mock .patch .dict (
2609
+ "os.environ" , {"GOOGLE_CLOUD_UNIVERSE_DOMAIN" : "" }
2610
+ ):
2611
+ tasks = build_from_document (
2612
+ discovery ,
2613
+ credentials = credentials ,
2614
+ )
2615
+
2616
+ def test_universe_env_var_configured_with_mtls (self ):
2617
+ fake_universe = "foo.com"
2618
+ discovery = read_datafile ("tasks.json" )
2619
+
2620
+ with self .assertRaises (MutualTLSChannelError ):
2621
+ with mock .patch .dict (
2622
+ "os.environ" ,
2623
+ {
2624
+ "GOOGLE_API_USE_MTLS_ENDPOINT" : "always" ,
2625
+ "GOOGLE_CLOUD_UNIVERSE_DOMAIN" : fake_universe ,
2626
+ },
2627
+ ):
2628
+ tasks = build_from_document (discovery )
2629
+
2630
+ def test_universe_env_var_configured_with_api_override (self ):
2631
+ fake_universe = "foo.com"
2632
+ fake_api_endpoint = "https://www.bar.com/"
2633
+ credentials = mock .Mock (universe_domain = fake_universe )
2634
+ discovery = read_datafile ("tasks.json" )
2635
+
2636
+ with mock .patch .dict (
2637
+ "os.environ" , {"GOOGLE_CLOUD_UNIVERSE_DOMAIN" : fake_universe }
2638
+ ):
2639
+ tasks = build_from_document (
2640
+ discovery ,
2641
+ credentials = credentials ,
2642
+ client_options = google .api_core .client_options .ClientOptions (
2643
+ api_endpoint = fake_api_endpoint
2644
+ ),
2645
+ )
2646
+
2647
+ assert tasks ._baseUrl == fake_api_endpoint
2648
+
2649
+ def test_universe_env_var_configured_with_client_options_universe (self ):
2650
+ fake_universe = "foo.com"
2651
+ another_fake_universe = "bar.com"
2652
+ credentials = mock .Mock (universe_domain = fake_universe )
2653
+ discovery = read_datafile ("tasks.json" )
2654
+
2655
+ with mock .patch .dict (
2656
+ "os.environ" , {"GOOGLE_CLOUD_UNIVERSE_DOMAIN" : another_fake_universe }
2657
+ ):
2658
+ tasks = build_from_document (
2659
+ discovery ,
2660
+ credentials = credentials ,
2661
+ client_options = google .api_core .client_options .ClientOptions (
2662
+ universe_domain = fake_universe
2663
+ ),
2664
+ )
2665
+
2666
+ assert tasks ._universe_domain == fake_universe
2667
+
2603
2668
2604
2669
if __name__ == "__main__" :
2605
2670
unittest .main ()
0 commit comments