Skip to content

Commit

Permalink
Merge pull request #1421 from dhermes/fix-1419
Browse files Browse the repository at this point in the history
Allowing missing tables key in BigQuery list tables response.
  • Loading branch information
dhermes committed Jan 28, 2016
2 parents d9c164a + d5744d3 commit 7e9dea2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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

0 comments on commit 7e9dea2

Please sign in to comment.