Skip to content

Commit

Permalink
Raising exception when dataset ID can't be implied in set_default...
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Feb 10, 2015
1 parent b395360 commit 06bc62f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def set_default_dataset_id(dataset_id=None):
:type dataset_id: string
:param dataset_id: Optional. The dataset ID to use as default.
:raises: :class:`EnvironmentError` if no dataset ID was implied.
"""
if dataset_id is None:
dataset_id = os.getenv(_DATASET_ENV_VAR_NAME)
Expand All @@ -92,6 +94,8 @@ def set_default_dataset_id(dataset_id=None):

if dataset_id is not None:
_implicit_environ.DATASET_ID = dataset_id
else:
raise EnvironmentError('No dataset ID could be implied.')


def set_default_connection(connection=None):
Expand Down
9 changes: 6 additions & 3 deletions gcloud/datastore/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_no_env_var_set(self):

with self._monkeyEnviron(None):
with self._monkeyImplicit():
self._callFUT()
self.assertRaises(EnvironmentError, self._callFUT)

self.assertEqual(_implicit_environ.DATASET_ID, None)

Expand Down Expand Up @@ -98,7 +98,7 @@ def test_set_explicit_None_wo_env_var_set(self):

with self._monkeyEnviron(None):
with self._monkeyImplicit():
self._callFUT(None)
self.assertRaises(EnvironmentError, self._callFUT, None)

self.assertEqual(_implicit_environ.DATASET_ID, None)

Expand Down Expand Up @@ -152,7 +152,10 @@ def _implicit_compute_engine_helper(self, status):

with self._monkeyEnviron(None):
with self._monkeyImplicit(connection=connection):
self._callFUT()
if EXPECTED_ID is None:
self.assertRaises(EnvironmentError, self._callFUT)
else:
self._callFUT()

self.assertEqual(_implicit_environ.DATASET_ID, EXPECTED_ID)
self.assertEqual(connection.host, '169.254.169.254')
Expand Down

0 comments on commit 06bc62f

Please sign in to comment.