diff --git a/gcloud/bigquery/table.py b/gcloud/bigquery/table.py index 07da7e34e2e3..56e4f7eebe7b 100644 --- a/gcloud/bigquery/table.py +++ b/gcloud/bigquery/table.py @@ -422,6 +422,8 @@ def _build_resource(self): resource['schema'] = { 'fields': _build_schema_resource(self._schema) } + else: + raise ValueError("Set either 'view_query' or 'schema'.") return resource diff --git a/gcloud/bigquery/test_table.py b/gcloud/bigquery/test_table.py index 16ce4de73334..dd50ce8ab466 100644 --- a/gcloud/bigquery/test_table.py +++ b/gcloud/bigquery/test_table.py @@ -437,6 +437,15 @@ def test_from_api_repr_w_properties(self): self.assertTrue(table._dataset._client is client) self._verifyResourceProperties(table, RESOURCE) + def test_create_no_view_query_no_schema(self): + conn = _Connection() + client = _Client(project=self.PROJECT, connection=conn) + dataset = _Dataset(client) + table = self._makeOne(self.TABLE_NAME, dataset) + + with self.assertRaises(ValueError): + table.create() + def test_create_w_bound_client(self): from gcloud.bigquery.table import SchemaField PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_NAME)