Skip to content

Move import to avoid possible ImportError. #1

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 6 additions & 3 deletions bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from apiclient.discovery import build
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials

from bigquery import logger

Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions bigquery/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down