Skip to content
Permalink
Browse files

feat: allow to use 'six.moves.collections_abc.Mapping' in 'client_opt…

…ions.from_dict()' (#943)
  • Loading branch information
paul1319 committed Jun 18, 2020
1 parent cc83ec2 commit 21af37b11ea2d6a89b3df484e1b2fa1d12849510
Showing with 22 additions and 9 deletions.
  1. +9 −9 googleapiclient/discovery.py
  2. +13 −0 tests/test_discovery.py
@@ -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.
@@ -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.
@@ -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
@@ -38,6 +38,7 @@
import re
import sys
import unittest2 as unittest
from collections import defaultdict

from parameterized import parameterized
import mock
@@ -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/"

0 comments on commit 21af37b

Please sign in to comment.
You can’t perform that action at this time.