Skip to content

Commit

Permalink
bigquery add DatasetReference class and tests (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
alixhami authored and tswast committed Sep 11, 2017
1 parent 26acfb5 commit 362684f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
36 changes: 36 additions & 0 deletions bigquery/google/cloud/bigquery/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,42 @@ def __repr__(self):
self.role, self.entity_type, self.entity_id)


class DatasetReference(object):
"""DatasetReferences are pointers to datasets.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets
:type project_id: str
:param project_id: the ID of the project
:type dataset_id: str
:param dataset_id: the ID of the dataset
"""

def __init__(self, project_id, dataset_id):
self._project_id = project_id
self._dataset_id = dataset_id

@property
def project_id(self):
"""Project ID of the dataset.
:rtype: str
:returns: the project ID.
"""
return self._project_id

@property
def dataset_id(self):
"""Dataset ID.
:rtype: str
:returns: the dataset ID.
"""
return self._dataset_id


class Dataset(object):
"""Datasets are containers for tables.
Expand Down
17 changes: 17 additions & 0 deletions bigquery/tests/unit/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ def test__eq___type_mismatch(self):
self.assertEqual(entry, mock.ANY)


class TestDatasetReference(unittest.TestCase):

@staticmethod
def _get_target_class():
from google.cloud.bigquery.dataset import DatasetReference

return DatasetReference

def _make_one(self, *args, **kw):
return self._get_target_class()(*args, **kw)

def test_ctor_defaults(self):
dataset_ref = self._make_one('some-project-1', 'dataset_1')
self.assertEqual(dataset_ref.project_id, 'some-project-1')
self.assertEqual(dataset_ref.dataset_id, 'dataset_1')


class TestDataset(unittest.TestCase):
PROJECT = 'project'
DS_NAME = 'dataset-name'
Expand Down

0 comments on commit 362684f

Please sign in to comment.