Skip to content

Commit

Permalink
Derive implicit dataset ID from environment.
Browse files Browse the repository at this point in the history
Base for #485.
  • Loading branch information
tseaver committed Jan 7, 2015
1 parent 9b64977 commit 10b7c9e
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 10b7c9e

Please sign in to comment.