Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to use 'six.moves.collections_abc.Mapping' in 'client_options.from_dict()' #943

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ def build(
cache_discovery: Boolean, whether or not to cache the discovery doc.
cache: googleapiclient.discovery_cache.base.CacheBase, an optional
cache object for the discovery documents.
client_options: Dictionary or google.api_core.client_options, Client options to set user
options on the client. API endpoint should be set through client_options.
client_cert_source is not supported, client cert should be provided using
client_encrypted_cert_source instead.
client_options: Mapping object or google.api_core.client_options, client
options to set user options on the client. The API endpoint should be set
through client_options. client_cert_source is not supported, client cert
should be provided using client_encrypted_cert_source instead.
adc_cert_path: str, client certificate file path to save the application
default client certificate for mTLS. This field is required if you want to
use the default client certificate.
Expand Down Expand Up @@ -359,10 +359,10 @@ def build_from_document(
credentials: oauth2client.Credentials or
google.auth.credentials.Credentials, credentials to be used for
authentication.
client_options: Dictionary or google.api_core.client_options, Client options to set user
options on the client. API endpoint should be set through client_options.
client_cert_source is not supported, client cert should be provided using
client_encrypted_cert_source instead.
client_options: Mapping object or google.api_core.client_options, client
options to set user options on the client. The API endpoint should be set
through client_options. client_cert_source is not supported, client cert
should be provided using client_encrypted_cert_source instead.
adc_cert_path: str, client certificate file path to save the application
default client certificate for mTLS. This field is required if you want to
use the default client certificate.
Expand Down Expand Up @@ -398,7 +398,7 @@ def build_from_document(
# If an API Endpoint is provided on client options, use that as the base URL
base = urljoin(service["rootUrl"], service["servicePath"])
if client_options:
if type(client_options) == dict:
if isinstance(client_options, six.moves.collections_abc.Mapping):
client_options = google.api_core.client_options.from_dict(client_options)
if client_options.api_endpoint:
base = client_options.api_endpoint
Expand Down
13 changes: 13 additions & 0 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import re
import sys
import unittest2 as unittest
from collections import defaultdict

from parameterized import parameterized
import mock
Expand Down Expand Up @@ -534,6 +535,18 @@ def test_api_endpoint_override_from_client_options(self):

self.assertEqual(plus._baseUrl, api_endpoint)

def test_api_endpoint_override_from_client_options_mapping_object(self):

discovery = open(datafile("plus.json")).read()
api_endpoint = "https://foo.googleapis.com/"
mapping_object = defaultdict(str)
mapping_object['api_endpoint'] = api_endpoint
plus = build_from_document(
discovery, client_options=mapping_object
)

self.assertEqual(plus._baseUrl, api_endpoint)

def test_api_endpoint_override_from_client_options_dict(self):
discovery = open(datafile("plus.json")).read()
api_endpoint = "https://foo.googleapis.com/"
Expand Down