def test_query_complete(self, get_query_mock): """Ensure that get_query_rows works when a query is complete.""" from bigquery.client import BigQueryClient bq = BigQueryClient(mock.Mock(), 'project') get_query_mock.return_value = { 'jobComplete': True, 'rows': [ {'f': [{'v': 'bar'}, {'v': 'man'}]}, {'f': [{'v': 'abc'}, {'v': 'xyz'}]} ], 'schema': { 'fields': [ {'name': 'foo', 'type': 'STRING'}, {'name': 'spider', 'type': 'STRING'} ] }, 'totalRows': 2 } result_rows = bq.get_query_rows(job_id=123, offset=0, limit=0) expected_rows = [{'foo': 'bar', 'spider': 'man'}, {'foo': 'abc', 'spider': 'xyz'}] self.assertEquals(result_rows, expected_rows)
def test_query_complete(self, get_query_mock): """Ensure that get_query_schema works when a query is complete.""" from bigquery.client import BigQueryClient bq = BigQueryClient(mock.Mock(), 'project') get_query_mock.return_value = { 'jobComplete': True, 'schema': {'fields': 'This is our schema'} } result_schema = bq.get_query_schema(job_id=123) self.assertEquals(result_schema, 'This is our schema')
def __init__(self, project_id, bigquery=bigquery, date_origin_default=DATE_ORIGIN_DEFAULT, date_str_len=DATE_STR_LEN, swallow_results=True): self.project_id = project_id self.date_origin_default = date_origin_default self.date_str_len = date_str_len self.gcb_client = bigquery.Client(project=project_id) credentials = GoogleCredentials.get_application_default() http = credentials.authorize(httplib2.Http()) service = build('bigquery', 'v2', http=http) self.bp_client = BigQueryClient(service, project_id, swallow_results)