diff --git a/gcloud/datastore/__init__.py b/gcloud/datastore/__init__.py index 1a2df8147706..6f77e05fba51 100644 --- a/gcloud/datastore/__init__.py +++ b/gcloud/datastore/__init__.py @@ -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) @@ -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 inferred.') def set_default_connection(connection=None): diff --git a/gcloud/datastore/test___init__.py b/gcloud/datastore/test___init__.py index 0ebc28a8927c..e4907862a10f 100644 --- a/gcloud/datastore/test___init__.py +++ b/gcloud/datastore/test___init__.py @@ -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) @@ -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) @@ -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')