Skip to content

Commit 3fcff41

Browse files
1 parent 4524943 commit 3fcff41

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

googleapiclient/discovery.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,15 @@
130130
STACK_QUERY_PARAMETERS = frozenset(["trace", "pp", "userip", "strict"])
131131
STACK_QUERY_PARAMETER_DEFAULT_VALUE = {"type": "string", "location": "query"}
132132

133+
133134
class APICoreVersionError(ValueError):
134135
def __init__(self):
135-
message = "google-api-core >= 2.18.0 is required to use the universe domain feature."
136+
message = (
137+
"google-api-core >= 2.18.0 is required to use the universe domain feature."
138+
)
136139
super().__init__(message)
137140

141+
138142
# Library-specific reserved words beyond Python keywords.
139143
RESERVED_WORDS = frozenset(["body"])
140144

@@ -448,12 +452,14 @@ def _retrieve_discovery_doc(
448452
cache.set(url, content)
449453
return content
450454

455+
451456
def _check_api_core_compatible_with_credentials_universe(credentials):
452457
if not HAS_UNIVERSE:
453458
credentials_universe = getattr(credentials, "universe_domain", None)
454459
if credentials_universe and credentials_universe != DEFAULT_UNIVERSE:
455460
raise APICoreVersionError
456461

462+
457463
@positional(1)
458464
def build_from_document(
459465
service,
@@ -630,7 +636,7 @@ def build_from_document(
630636
):
631637
credentials = credentials.with_always_use_jwt_access(always_use_jwt_access)
632638
credentials._create_self_signed_jwt(audience_for_self_signed_jwt)
633-
639+
634640
# If credentials are provided, create an authorized http instance;
635641
# otherwise, skip authentication.
636642
if credentials:

tests/test_discovery.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
STACK_QUERY_PARAMETERS,
7171
V1_DISCOVERY_URI,
7272
V2_DISCOVERY_URI,
73-
ResourceMethodParameters,
7473
APICoreVersionError,
74+
ResourceMethodParameters,
7575
_fix_up_media_path_base_url,
7676
_fix_up_media_upload,
7777
_fix_up_method_description,
@@ -543,6 +543,7 @@ def test_credentials_and_credentials_file_mutually_exclusive(self):
543543
class DiscoveryFromDocument(unittest.TestCase):
544544
MOCK_CREDENTIALS = mock.Mock(spec=google.auth.credentials.Credentials)
545545
MOCK_CREDENTIALS.universe_domain = None
546+
546547
def test_can_build_from_local_document(self):
547548
discovery = read_datafile("plus.json")
548549
plus = build_from_document(
@@ -2347,9 +2348,9 @@ def test_get_media(self):
23472348
self.assertEqual(b"standing in for media", response)
23482349

23492350

2350-
23512351
class Universe(unittest.TestCase):
23522352
if HAS_UNIVERSE:
2353+
23532354
def test_validate_credentials_with_no_client_options(self):
23542355
http = build_http()
23552356
discovery = read_datafile("zoo.json")
@@ -2671,7 +2672,9 @@ def test_universe_env_var_configured_with_client_options_universe(self):
26712672
)
26722673

26732674
assert tasks._universe_domain == fake_universe
2675+
26742676
else:
2677+
26752678
def test_client_options_universe_with_older_version_of_api_core(self):
26762679
fake_universe = "foo.com"
26772680
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
@@ -2686,7 +2689,6 @@ def test_client_options_universe_with_older_version_of_api_core(self):
26862689
),
26872690
)
26882691

2689-
26902692
def test_credentials_universe_with_older_version_of_api_core(self):
26912693
fake_universe = "foo.com"
26922694
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
@@ -2697,7 +2699,7 @@ def test_credentials_universe_with_older_version_of_api_core(self):
26972699
discovery,
26982700
credentials=credentials,
26992701
)
2700-
2702+
27012703
def test_credentials_default_universe_with_older_version_of_api_core(self):
27022704
credentials = mock.Mock(spec=google.auth.credentials.Credentials)
27032705
credentials.universe_domain = "googleapis.com"
@@ -2706,29 +2708,30 @@ def test_credentials_default_universe_with_older_version_of_api_core(self):
27062708
discovery,
27072709
credentials=credentials,
27082710
)
2709-
2711+
27102712
def test_http_credentials_universe_with_older_version_of_api_core(self):
27112713
fake_universe = "foo.com"
27122714
http = google_auth_httplib2.AuthorizedHttp(
2713-
credentials=mock.Mock(universe_domain=fake_universe), http=build_http()
2714-
)
2715+
credentials=mock.Mock(universe_domain=fake_universe), http=build_http()
2716+
)
27152717
discovery = read_datafile("tasks.json")
27162718
with self.assertRaises(APICoreVersionError):
27172719
tasks = build_from_document(
27182720
discovery,
27192721
http=http,
27202722
)
2721-
2723+
27222724
def test_http_credentials_default_universe_with_older_version_of_api_core(self):
27232725
http = google_auth_httplib2.AuthorizedHttp(
2724-
credentials=mock.Mock(universe_domain="googleapis.com"), http=build_http()
2725-
)
2726+
credentials=mock.Mock(universe_domain="googleapis.com"),
2727+
http=build_http(),
2728+
)
27262729
discovery = read_datafile("tasks.json")
27272730
tasks = build_from_document(
27282731
discovery,
27292732
http=http,
27302733
)
2731-
2734+
27322735

27332736
if __name__ == "__main__":
27342737
unittest.main()

0 commit comments

Comments
 (0)