Skip to content

Commit

Permalink
Merge pull request #493 from tseaver/implicit_dataset_id
Browse files Browse the repository at this point in the history
Derive implicit dataset ID from environment.
  • Loading branch information
dhermes committed Jan 7, 2015
2 parents 9b64977 + 10b7c9e commit 8faba35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def set_default_dataset(dataset_id=None):
dataset_id = os.getenv(_DATASET_ENV_VAR_NAME)

if dataset_id is not None:
_implicit_environ.DATASET_ID = dataset_id
_implicit_environ.DATASET = get_dataset(dataset_id)


Expand Down
3 changes: 3 additions & 0 deletions gcloud/datastore/_implicit_environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"""


DATASET_ID = None
"""Module global to allow persistent implied dataset ID from enviroment."""

DATASET = None
"""Module global to allow persistent implied dataset from enviroment."""

Expand Down
6 changes: 6 additions & 0 deletions gcloud/datastore/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,26 @@ def custom_get_dataset(local_dataset_id):

def test_set_from_env_var(self):
from gcloud.datastore import _DATASET_ENV_VAR_NAME
from gcloud.datastore import _implicit_environ

# Make a custom getenv function to Monkey.
DATASET = 'dataset'
VALUES = {
_DATASET_ENV_VAR_NAME: DATASET,
}
self._test_with_environ(VALUES, DATASET)
self.assertEqual(_implicit_environ.DATASET_ID, DATASET)

def test_no_env_var_set(self):
from gcloud.datastore import _implicit_environ
self._test_with_environ({}, None)
self.assertEqual(_implicit_environ.DATASET_ID, None)

def test_set_explicit(self):
from gcloud.datastore import _implicit_environ
DATASET_ID = 'DATASET'
self._test_with_environ({}, DATASET_ID, dataset_id=DATASET_ID)
self.assertEqual(_implicit_environ.DATASET_ID, DATASET_ID)


class Test_set_default_connection(unittest2.TestCase):
Expand Down

0 comments on commit 8faba35

Please sign in to comment.