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

Allowing missing tables key in BigQuery list tables response. #1421

Merged
merged 1 commit into from
Jan 28, 2016
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
2 changes: 1 addition & 1 deletion gcloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def list_tables(self, max_results=None, page_token=None):
resp = connection.api_request(method='GET', path=path,
query_params=params)
tables = [Table.from_api_repr(resource, self)
for resource in resp['tables']]
for resource in resp.get('tables', ())]
return tables, resp.get('nextPageToken')

def table(self, name, schema=()):
Expand Down
19 changes: 17 additions & 2 deletions gcloud/bigquery/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,24 @@ def test_delete_w_alternate_client(self):
self.assertEqual(req['method'], 'DELETE')
self.assertEqual(req['path'], '/%s' % PATH)

def test_list_tables_defaults(self):
def test_list_tables_empty(self):
from gcloud.bigquery.table import Table

conn = _Connection({})
client = _Client(project=self.PROJECT, connection=conn)
dataset = self._makeOne(self.DS_NAME, client=client)
tables, token = dataset.list_tables()
self.assertEqual(tables, [])
self.assertEqual(token, None)
self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'GET')
PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_NAME)
self.assertEqual(req['path'], '/%s' % PATH)

def test_list_tables_defaults(self):
from gcloud.bigquery.table import Table

TABLE_1 = 'table_one'
TABLE_2 = 'table_two'
PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_NAME)
Expand Down Expand Up @@ -657,7 +672,7 @@ def test_list_tables_defaults(self):

def test_list_tables_explicit(self):
from gcloud.bigquery.table import Table
conn = _Connection({})

TABLE_1 = 'table_one'
TABLE_2 = 'table_two'
PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_NAME)
Expand Down
7 changes: 7 additions & 0 deletions system_tests/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def test_list_tables(self):
self.assertFalse(dataset.exists())
dataset.create()
self.to_delete.append(dataset)

# Retrieve tables before any are created for the dataset.
all_tables, token = dataset.list_tables()
self.assertEqual(all_tables, [])
self.assertEqual(token, None)

# Insert some tables to be listed.
tables_to_create = [
'new%d' % (1000 * time.time(),),
'newer%d' % (1000 * time.time(),),
Expand Down