107
107
108
108
DATA_DIR = os .path .join (os .path .dirname (__file__ ), "data" )
109
109
110
+ def _reset_universe_domain (credentials , universe_domain = None ):
111
+ if hasattr (credentials , "universe_domain" ):
112
+ credentials .universe_domain = universe_domain
110
113
111
114
def assertUrisEqual (testcase , expected , actual ):
112
115
"""Test that URIs are the same, up to reordering of query parameters."""
@@ -542,7 +545,8 @@ def test_credentials_and_credentials_file_mutually_exclusive(self):
542
545
543
546
class DiscoveryFromDocument (unittest .TestCase ):
544
547
MOCK_CREDENTIALS = mock .Mock (spec = google .auth .credentials .Credentials )
545
- MOCK_CREDENTIALS .universe_domain = None
548
+ _reset_universe_domain (MOCK_CREDENTIALS )
549
+
546
550
def test_can_build_from_local_document (self ):
547
551
discovery = read_datafile ("plus.json" )
548
552
plus = build_from_document (
@@ -694,7 +698,7 @@ def test_scopes_from_client_options(self):
694
698
discovery = read_datafile ("plus.json" )
695
699
696
700
with mock .patch ("googleapiclient._auth.default_credentials" ) as default :
697
- default .return_value . universe_domain = None
701
+ _reset_universe_domain ( default .return_value )
698
702
plus = build_from_document (
699
703
discovery ,
700
704
client_options = {"scopes" : ["1" , "2" ]},
@@ -706,7 +710,7 @@ def test_quota_project_from_client_options(self):
706
710
discovery = read_datafile ("plus.json" )
707
711
708
712
with mock .patch ("googleapiclient._auth.default_credentials" ) as default :
709
- default .return_value . universe_domain = None
713
+ _reset_universe_domain ( default .return_value )
710
714
plus = build_from_document (
711
715
discovery ,
712
716
client_options = google .api_core .client_options .ClientOptions (
@@ -720,7 +724,7 @@ def test_credentials_file_from_client_options(self):
720
724
discovery = read_datafile ("plus.json" )
721
725
722
726
with mock .patch ("googleapiclient._auth.credentials_from_file" ) as default :
723
- default .return_value . universe_domain = None
727
+ _reset_universe_domain ( default .return_value )
724
728
plus = build_from_document (
725
729
discovery ,
726
730
client_options = google .api_core .client_options .ClientOptions (
@@ -776,7 +780,7 @@ def test_self_signed_jwt_disabled(self):
776
780
777
781
class DiscoveryFromDocumentMutualTLS (unittest .TestCase ):
778
782
MOCK_CREDENTIALS = mock .Mock (spec = google .auth .credentials .Credentials )
779
- MOCK_CREDENTIALS . universe_domain = None
783
+ _reset_universe_domain ( MOCK_CREDENTIALS )
780
784
ADC_CERT_PATH = "adc_cert_path"
781
785
ADC_KEY_PATH = "adc_key_path"
782
786
ADC_PASSPHRASE = "adc_passphrase"
@@ -1533,7 +1537,7 @@ def test_plus_resources(self):
1533
1537
@unittest .skipIf (not HAS_OAUTH2CLIENT , "oauth2client unavailable." )
1534
1538
def test_oauth2client_credentials (self ):
1535
1539
credentials = mock .Mock (spec = GoogleCredentials )
1536
- credentials . universe_domain = None
1540
+ _reset_universe_domain ( credentials )
1537
1541
credentials .create_scoped_required .return_value = False
1538
1542
1539
1543
discovery = read_datafile ("plus.json" )
@@ -1542,7 +1546,7 @@ def test_oauth2client_credentials(self):
1542
1546
1543
1547
def test_google_auth_credentials (self ):
1544
1548
credentials = mock .Mock (spec = google .auth .credentials .Credentials )
1545
- credentials . universe_domain = None
1549
+ _reset_universe_domain ( credentials )
1546
1550
discovery = read_datafile ("plus.json" )
1547
1551
service = build_from_document (discovery , credentials = credentials )
1548
1552
@@ -2671,21 +2675,22 @@ def test_universe_env_var_configured_with_client_options_universe(self):
2671
2675
)
2672
2676
2673
2677
assert tasks ._universe_domain == fake_universe
2678
+
2674
2679
else :
2675
- def test_client_options_universe_with_older_version_of_api_core ( self ):
2676
- fake_universe = "foo.com"
2677
- credentials = mock . Mock ( spec = google . auth . credentials . Credentials )
2678
- credentials . universe_domain = fake_universe
2679
- discovery = read_datafile ( "tasks.json" )
2680
- with self . assertRaises ( APICoreVersionError ):
2681
- tasks = build_from_document (
2682
- discovery ,
2683
- credentials = credentials ,
2684
- client_options = google . api_core . client_options . ClientOptions (
2685
- universe_domain = fake_universe
2686
- ),
2687
- )
2688
-
2680
+ if hasattr ( google . api_core . client_options . ClientOptions , "universe_domain" ):
2681
+ def test_client_options_universe_with_older_version_of_api_core ( self ):
2682
+ fake_universe = "foo.com"
2683
+ credentials = mock . Mock ( spec = google . auth . credentials . Credentials )
2684
+ credentials . universe_domain = fake_universe
2685
+ discovery = read_datafile ( "tasks.json" )
2686
+ with self . assertRaises ( APICoreVersionError ):
2687
+ tasks = build_from_document (
2688
+ discovery ,
2689
+ credentials = credentials ,
2690
+ client_options = google . api_core . client_options . ClientOptions (
2691
+ universe_domain = fake_universe
2692
+ ),
2693
+ )
2689
2694
2690
2695
def test_credentials_universe_with_older_version_of_api_core (self ):
2691
2696
fake_universe = "foo.com"
0 commit comments