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

bigquery add DatasetReference class and tests #3938

Merged
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
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