From f1094d7277fff1dccf4f6f73c2733533bcacf039 Mon Sep 17 00:00:00 2001 From: "Steven.Osborne" Date: Tue, 13 May 2014 16:45:38 -0500 Subject: [PATCH] Move import to avoid possible ImportError. --- bigquery/client.py | 9 ++++++--- bigquery/tests/test_client.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bigquery/client.py b/bigquery/client.py index 50fbd46..0527c62 100644 --- a/bigquery/client.py +++ b/bigquery/client.py @@ -4,7 +4,6 @@ from apiclient.discovery import build import httplib2 -from oauth2client.client import SignedJwtAssertionCredentials from bigquery import logger @@ -53,8 +52,7 @@ def _get_bq_service(credentials=None, service_account=None, private_key=None, if not credentials: scope = BIGQUERY_SCOPE_READ_ONLY if readonly else BIGQUERY_SCOPE - credentials = SignedJwtAssertionCredentials( - service_account, private_key, scope=scope) + credentials = _credentials(service_account, private_key, scope=scope) http = httplib2.Http() http = credentials.authorize(http) @@ -63,6 +61,11 @@ def _get_bq_service(credentials=None, service_account=None, private_key=None, return service +def _credentials(): + from oauth2client.client import SignedJwtAssertionCredentials + return SignedJwtAssertionCredentials + + class BigQueryClient(object): def __init__(self, bq_service, project_id): diff --git a/bigquery/tests/test_client.py b/bigquery/tests/test_client.py index 1944256..458f4bc 100644 --- a/bigquery/tests/test_client.py +++ b/bigquery/tests/test_client.py @@ -22,7 +22,7 @@ def test_no_credentials(self): self.assertRaises(Exception, client.get_client, 'foo', 'bar') - @mock.patch('bigquery.client.SignedJwtAssertionCredentials') + @mock.patch('bigquery.client._credentials') @mock.patch('bigquery.client.build') def test_initialize_readonly(self, mock_build, mock_cred): """Ensure that a BigQueryClient is initialized and returned with @@ -49,7 +49,7 @@ def test_initialize_readonly(self, mock_build, mock_cred): self.assertEquals(mock_bq, bq_client.bigquery) self.assertEquals(project_id, bq_client.project_id) - @mock.patch('bigquery.client.SignedJwtAssertionCredentials') + @mock.patch('bigquery.client._credentials') @mock.patch('bigquery.client.build') def test_initialize_read_write(self, mock_build, mock_cred): """Ensure that a BigQueryClient is initialized and returned with