diff --git a/gcloud/datastore/__init__.py b/gcloud/datastore/__init__.py index b0fc7e854b66..c48065e600e6 100644 --- a/gcloud/datastore/__init__.py +++ b/gcloud/datastore/__init__.py @@ -99,7 +99,7 @@ def set_default_dataset_id(dataset_id=None): dataset_id = _implicit_environ.compute_engine_id() if dataset_id is not None: - _implicit_environ.DATASET_ID = dataset_id + _implicit_environ._DEFAULTS.dataset_id = dataset_id else: raise EnvironmentError('No dataset ID could be inferred.') @@ -111,7 +111,7 @@ def set_default_connection(connection=None): :param connection: A connection provided to be the default. """ connection = connection or get_connection() - _implicit_environ.CONNECTION = connection + _implicit_environ._DEFAULTS.connection = connection def set_defaults(dataset_id=None, connection=None): diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py index 2af5b6490295..7a00794708ad 100644 --- a/gcloud/datastore/_implicit_environ.py +++ b/gcloud/datastore/_implicit_environ.py @@ -28,11 +28,19 @@ app_identity = None -DATASET_ID = None -"""Module global to allow persistent implied dataset ID from enviroment.""" +class _DefaultsContainer(object): + """Container for defaults. -CONNECTION = None -"""Module global to allow persistent implied connection from enviroment.""" + :type connection: :class:`gcloud.datastore.connection.Connection` + :param connection: Persistent implied connection from environment. + + :type dataset_id: string + :param dataset_id: Persistent implied dataset ID from environment. + """ + + def __init__(self, connection=None, dataset_id=None): + self.connection = connection + self.dataset_id = dataset_id def app_engine_id(): @@ -87,7 +95,7 @@ def get_default_connection(): :rtype: :class:`gcloud.datastore.connection.Connection` or ``NoneType`` :returns: The default connection if one has been set. """ - return CONNECTION + return _DEFAULTS.connection def get_default_dataset_id(): @@ -96,4 +104,7 @@ def get_default_dataset_id(): :rtype: string or ``NoneType`` :returns: The default dataset ID if one has been set. """ - return DATASET_ID + return _DEFAULTS.dataset_id + + +_DEFAULTS = _DefaultsContainer() diff --git a/gcloud/datastore/test___init__.py b/gcloud/datastore/test___init__.py index 140bbddc3a93..d983706d3334 100644 --- a/gcloud/datastore/test___init__.py +++ b/gcloud/datastore/test___init__.py @@ -19,12 +19,13 @@ class Test_set_default_dataset_id(unittest2.TestCase): def setUp(self): from gcloud.datastore import _implicit_environ - self._replaced_dataset_id = _implicit_environ.DATASET_ID - _implicit_environ.DATASET_ID = None + self._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( + None, None) def tearDown(self): from gcloud.datastore import _implicit_environ - _implicit_environ.DATASET_ID = self._replaced_dataset_id + _implicit_environ._DEFAULTS = self._replaced_defaults def _callFUT(self, dataset_id=None): from gcloud.datastore import set_default_dataset_id @@ -60,7 +61,7 @@ def test_no_env_var_set(self): with self._monkeyImplicit(): self.assertRaises(EnvironmentError, self._callFUT) - self.assertEqual(_implicit_environ.DATASET_ID, None) + self.assertEqual(_implicit_environ.get_default_dataset_id(), None) def test_set_from_env_var(self): from gcloud.datastore import _implicit_environ @@ -70,7 +71,8 @@ def test_set_from_env_var(self): with self._monkeyImplicit(): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, IMPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + IMPLICIT_DATASET_ID) def test_set_explicit_w_env_var_set(self): from gcloud.datastore import _implicit_environ @@ -80,7 +82,8 @@ def test_set_explicit_w_env_var_set(self): with self._monkeyImplicit(): self._callFUT(EXPLICIT_DATASET_ID) - self.assertEqual(_implicit_environ.DATASET_ID, EXPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + EXPLICIT_DATASET_ID) def test_set_explicit_no_env_var_set(self): from gcloud.datastore import _implicit_environ @@ -91,7 +94,8 @@ def test_set_explicit_no_env_var_set(self): with self._monkeyImplicit(): self._callFUT(EXPLICIT_DATASET_ID) - self.assertEqual(_implicit_environ.DATASET_ID, EXPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + EXPLICIT_DATASET_ID) def test_set_explicit_None_wo_env_var_set(self): from gcloud.datastore import _implicit_environ @@ -100,7 +104,7 @@ def test_set_explicit_None_wo_env_var_set(self): with self._monkeyImplicit(): self.assertRaises(EnvironmentError, self._callFUT, None) - self.assertEqual(_implicit_environ.DATASET_ID, None) + self.assertEqual(_implicit_environ.get_default_dataset_id(), None) def test_set_explicit_None_w_env_var_set(self): from gcloud.datastore import _implicit_environ @@ -110,7 +114,8 @@ def test_set_explicit_None_w_env_var_set(self): with self._monkeyImplicit(): self._callFUT(None) - self.assertEqual(_implicit_environ.DATASET_ID, IMPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + IMPLICIT_DATASET_ID) def test_set_from_gcd_env_var(self): from gcloud.datastore import _GCD_DATASET_ENV_VAR_NAME @@ -123,7 +128,8 @@ def test_set_from_gcd_env_var(self): with self._monkeyImplicit(): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, GCD_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + GCD_DATASET_ID) def test_set_gcd_and_production_env_vars(self): from gcloud.datastore import _DATASET_ENV_VAR_NAME @@ -141,8 +147,8 @@ def test_set_gcd_and_production_env_vars(self): with self._monkeyImplicit(): self._callFUT() - self.assertNotEqual(_implicit_environ.DATASET_ID, GCD_DATASET_ID) - self.assertEqual(_implicit_environ.DATASET_ID, IMPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + IMPLICIT_DATASET_ID) def test_set_gcd_env_vars_and_appengine(self): from gcloud.datastore import _GCD_DATASET_ENV_VAR_NAME @@ -158,8 +164,8 @@ def test_set_gcd_env_vars_and_appengine(self): with self._monkeyImplicit(app_identity=APP_IDENTITY): self._callFUT() - self.assertNotEqual(_implicit_environ.DATASET_ID, APP_ENGINE_ID) - self.assertEqual(_implicit_environ.DATASET_ID, GCD_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + GCD_DATASET_ID) def test_set_implicit_from_appengine(self): from gcloud.datastore import _implicit_environ @@ -171,7 +177,8 @@ def test_set_implicit_from_appengine(self): with self._monkeyImplicit(app_identity=APP_IDENTITY): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, APP_ENGINE_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + APP_ENGINE_ID) def test_set_implicit_both_env_and_appengine(self): from gcloud.datastore import _implicit_environ @@ -183,7 +190,8 @@ def test_set_implicit_both_env_and_appengine(self): with self._monkeyImplicit(app_identity=APP_IDENTITY): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, IMPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + IMPLICIT_DATASET_ID) def _implicit_compute_engine_helper(self, status): from gcloud.datastore import _implicit_environ @@ -206,7 +214,8 @@ def _implicit_compute_engine_helper(self, status): else: self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, EXPECTED_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + EXPECTED_ID) self.assertEqual(connection.host, '169.254.169.254') self.assertEqual(connection.timeout, 0.1) self.assertEqual( @@ -241,7 +250,8 @@ def test_set_implicit_both_appengine_and_compute(self): app_identity=APP_IDENTITY): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, APP_ENGINE_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + APP_ENGINE_ID) self.assertEqual(connection.host, None) self.assertEqual(connection.timeout, None) @@ -257,7 +267,8 @@ def test_set_implicit_three_env_appengine_and_compute(self): app_identity=APP_IDENTITY): self._callFUT() - self.assertEqual(_implicit_environ.DATASET_ID, IMPLICIT_DATASET_ID) + self.assertEqual(_implicit_environ.get_default_dataset_id(), + IMPLICIT_DATASET_ID) self.assertEqual(connection.host, None) self.assertEqual(connection.timeout, None) @@ -266,12 +277,13 @@ class Test_set_default_connection(unittest2.TestCase): def setUp(self): from gcloud.datastore import _implicit_environ - self._replaced_connection = _implicit_environ.CONNECTION - _implicit_environ.CONNECTION = None + self._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( + None, None) def tearDown(self): from gcloud.datastore import _implicit_environ - _implicit_environ.CONNECTION = self._replaced_connection + _implicit_environ._DEFAULTS = self._replaced_defaults def _callFUT(self, connection=None): from gcloud.datastore import set_default_connection @@ -280,23 +292,23 @@ def _callFUT(self, connection=None): def test_set_explicit(self): from gcloud.datastore import _implicit_environ - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) fake_cnxn = object() self._callFUT(connection=fake_cnxn) - self.assertEqual(_implicit_environ.CONNECTION, fake_cnxn) + self.assertEqual(_implicit_environ.get_default_connection(), fake_cnxn) def test_set_implicit(self): from gcloud._testing import _Monkey from gcloud import datastore from gcloud.datastore import _implicit_environ - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) fake_cnxn = object() with _Monkey(datastore, get_connection=lambda: fake_cnxn): self._callFUT() - self.assertEqual(_implicit_environ.CONNECTION, fake_cnxn) + self.assertEqual(_implicit_environ.get_default_connection(), fake_cnxn) class Test_set_defaults(unittest2.TestCase): diff --git a/gcloud/datastore/test__implicit_environ.py b/gcloud/datastore/test__implicit_environ.py index 7352cb13b2a5..b7dcd37733de 100644 --- a/gcloud/datastore/test__implicit_environ.py +++ b/gcloud/datastore/test__implicit_environ.py @@ -29,7 +29,8 @@ def test_preset(self): from gcloud.datastore import _implicit_environ SENTINEL = object() - with _Monkey(_implicit_environ, CONNECTION=SENTINEL): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(SENTINEL, None) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): self.assertEqual(self._callFUT(), SENTINEL) @@ -47,5 +48,6 @@ def test_preset(self): from gcloud.datastore import _implicit_environ SENTINEL = object() - with _Monkey(_implicit_environ, DATASET_ID=SENTINEL): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, SENTINEL) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): self.assertEqual(self._callFUT(), SENTINEL) diff --git a/gcloud/datastore/test_api.py b/gcloud/datastore/test_api.py index 5edb03f6ae95..a5c0a6a5e335 100644 --- a/gcloud/datastore/test_api.py +++ b/gcloud/datastore/test_api.py @@ -28,7 +28,8 @@ def _callFUT(self, passed=_MARKER, first_key=None): def _monkey(self, dataset_id): from gcloud.datastore import _implicit_environ from gcloud._testing import _Monkey - return _Monkey(_implicit_environ, DATASET_ID=dataset_id) + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, dataset_id) + return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) def test_implicit_unset_wo_keys(self): with self._monkey(None): @@ -122,7 +123,8 @@ def _callFUT(self, passed=_MARKER): def _monkey(self, connection): from gcloud.datastore import _implicit_environ from gcloud._testing import _Monkey - return _Monkey(_implicit_environ, CONNECTION=connection) + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) + return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) def test_implicit_unset(self): with self._monkey(None): @@ -471,8 +473,9 @@ def test_implicit_wo_transaction(self): CUSTOM_CONNECTION = _Connection(entity_pb) key = Key(KIND, ID, dataset_id=DATASET_ID) - with _Monkey(_implicit_environ, CONNECTION=CUSTOM_CONNECTION, - DATASET_ID=DATASET_ID): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, + DATASET_ID) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): result, = self._callFUT([key]) expected_called_with = { @@ -577,7 +580,7 @@ def test_no_connection(self): entity = _Entity(foo=u'bar') entity.key = _Key(_DATASET) - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) with self.assertRaises(EnvironmentError): self._callFUT([entity], dataset_id=_DATASET) @@ -593,7 +596,7 @@ def test_no_dataset_id(self): entity = _Entity(foo=u'bar') entity.key = _Key(_DATASET) - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) result = self._callFUT([entity], connection=connection) self.assertEqual(result, None) @@ -610,7 +613,7 @@ def test_no_dataset_id(self): def test_no_entities(self): from gcloud.datastore import _implicit_environ - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) result = self._callFUT([]) self.assertEqual(result, None) @@ -677,7 +680,8 @@ def test_implicit_connection(self): entity = _Entity(foo=u'bar') key = entity.key = _Key(_DATASET) - with _Monkey(_implicit_environ, CONNECTION=connection): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): # Set up Batch on stack so we can check it is used. with _NoCommitBatch(_DATASET, connection) as CURR_BATCH: result = self._callFUT([entity]) @@ -708,7 +712,7 @@ def test_no_connection(self): _DATASET = 'DATASET' key = _Key(_DATASET) - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) with self.assertRaises(EnvironmentError): self._callFUT([key], dataset_id=_DATASET) @@ -722,7 +726,7 @@ def test_no_dataset_id(self): connection = _Connection() key = _Key(_DATASET) - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) result = self._callFUT([key], connection=connection) @@ -735,7 +739,7 @@ def test_no_dataset_id(self): def test_no_keys(self): from gcloud.datastore import _implicit_environ - self.assertEqual(_implicit_environ.CONNECTION, None) + self.assertEqual(_implicit_environ.get_default_connection(), None) result = self._callFUT([]) self.assertEqual(result, None) @@ -768,9 +772,9 @@ def test_wo_batch_w_key_different_than_default_dataset_id(self): connection = _Connection() key = _Key(_DATASET) - with _Monkey(_implicit_environ, - CONNECTION=connection, - DATASET_ID=_DEFAULT_DATASET): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, + _DEFAULT_DATASET) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): result = self._callFUT([key]) self.assertEqual(result, None) self.assertEqual(len(connection._committed), 1) @@ -831,9 +835,9 @@ def test_implicit_connection_and_dataset_id(self): connection = _Connection() key = _Key(_DATASET) - with _Monkey(_implicit_environ, - CONNECTION=connection, - DATASET_ID=_DATASET): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, + _DATASET) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): # Set up Batch on stack so we can check it is used. with _NoCommitBatch(_DATASET, connection) as CURR_BATCH: result = self._callFUT([key]) @@ -878,8 +882,9 @@ def test_w_implicit_connection(self): CUSTOM_CONNECTION = _Connection() NUM_IDS = 2 - with _Monkey(_implicit_environ, CONNECTION=CUSTOM_CONNECTION, - DATASET_ID='DATASET'): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, + 'DATASET') + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): INCOMPLETE_KEY = Key('KIND') result = self._callFUT(INCOMPLETE_KEY, NUM_IDS) @@ -893,8 +898,9 @@ def test_with_already_completed_key(self): from gcloud._testing import _Monkey CUSTOM_CONNECTION = _Connection() - with _Monkey(_implicit_environ, CONNECTION=CUSTOM_CONNECTION, - DATASET_ID='DATASET'): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, + 'DATASET') + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): COMPLETE_KEY = Key('KIND', 1234) self.assertRaises(ValueError, self._callFUT, COMPLETE_KEY, 2) diff --git a/gcloud/datastore/test_batch.py b/gcloud/datastore/test_batch.py index 9f3a1b70dfb8..a82fad2347be 100644 --- a/gcloud/datastore/test_batch.py +++ b/gcloud/datastore/test_batch.py @@ -30,9 +30,8 @@ def test_ctor_missing_required(self): from gcloud._testing import _Monkey from gcloud.datastore import _implicit_environ - with _Monkey(_implicit_environ, - DATASET_ID=None, - CONNECTION=None): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, None) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): self.assertRaises(ValueError, self._makeOne) self.assertRaises(ValueError, self._makeOne, dataset_id=object()) self.assertRaises(ValueError, self._makeOne, connection=object()) @@ -52,15 +51,15 @@ def test_ctor_implicit(self): from gcloud._testing import _Monkey from gcloud.datastore import _implicit_environ from gcloud.datastore._datastore_v1_pb2 import Mutation - DATASET_ID = 'DATASET' + _DATASET = 'DATASET' CONNECTION = _Connection() - with _Monkey(_implicit_environ, - DATASET_ID=DATASET_ID, - CONNECTION=CONNECTION): + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CONNECTION, + _DATASET) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): batch = self._makeOne() - self.assertEqual(batch.dataset_id, DATASET_ID) + self.assertEqual(batch.dataset_id, _DATASET) self.assertEqual(batch.connection, CONNECTION) self.assertTrue(isinstance(batch.mutation, Mutation)) self.assertEqual(batch._auto_id_entities, []) diff --git a/gcloud/datastore/test_entity.py b/gcloud/datastore/test_entity.py index d7c1272e27b8..5ec05d3b670e 100644 --- a/gcloud/datastore/test_entity.py +++ b/gcloud/datastore/test_entity.py @@ -23,12 +23,13 @@ class TestEntity(unittest2.TestCase): def setUp(self): from gcloud.datastore import _implicit_environ - self._replaced_dataset_id = _implicit_environ.DATASET_ID - _implicit_environ.DATASET_ID = None + self._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( + None, None) def tearDown(self): from gcloud.datastore import _implicit_environ - _implicit_environ.DATASET_ID = self._replaced_dataset_id + _implicit_environ._DEFAULTS = self._replaced_defaults def _getTargetClass(self): from gcloud.datastore.entity import Entity diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index 7c518cf7e586..95bdefcb2303 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -19,12 +19,13 @@ class Test_entity_from_protobuf(unittest2.TestCase): def setUp(self): from gcloud.datastore import _implicit_environ - self._replaced_dataset_id = _implicit_environ.DATASET_ID - _implicit_environ.DATASET_ID = None + self._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( + None, None) def tearDown(self): from gcloud.datastore import _implicit_environ - _implicit_environ.DATASET_ID = self._replaced_dataset_id + _implicit_environ._DEFAULTS = self._replaced_defaults def _callFUT(self, val): from gcloud.datastore.helpers import entity_from_protobuf diff --git a/gcloud/datastore/test_key.py b/gcloud/datastore/test_key.py index 1065c6e31878..36edab88861d 100644 --- a/gcloud/datastore/test_key.py +++ b/gcloud/datastore/test_key.py @@ -20,14 +20,14 @@ class TestKey(unittest2.TestCase): _DEFAULT_DATASET = 'DATASET' def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_dataset_id = _implicit_environ.DATASET_ID - _implicit_environ.DATASET_ID = None + self._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( + None, None) def tearDown(self): from gcloud.datastore import _implicit_environ - _implicit_environ.DATASET_ID = self._replaced_dataset_id + _implicit_environ._DEFAULTS = self._replaced_defaults def _getTargetClass(self): from gcloud.datastore.key import Key @@ -39,7 +39,8 @@ def _makeOne(self, *args, **kwargs): def _monkeyDatasetID(self, dataset_id=_DEFAULT_DATASET): from gcloud._testing import _Monkey from gcloud.datastore import _implicit_environ - return _Monkey(_implicit_environ, DATASET_ID=dataset_id) + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, dataset_id) + return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) def test_ctor_empty(self): self.assertRaises(ValueError, self._makeOne) diff --git a/gcloud/datastore/test_query.py b/gcloud/datastore/test_query.py index c27deede9ff6..3c7727acb2e1 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -31,7 +31,9 @@ def test_ctor_defaults_w_implicit_dataset_id(self): from gcloud._testing import _Monkey from gcloud.datastore import _implicit_environ _DATASET = 'DATASET' - with _Monkey(_implicit_environ, DATASET_ID=_DATASET): + + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, _DATASET) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): query = self._makeOne() self.assertEqual(query.dataset_id, _DATASET) self.assertEqual(query.kind, None) @@ -319,7 +321,9 @@ def test_fetch_defaults_w_implicit_connection(self): _KIND = 'KIND' connection = _Connection() query = self._makeOne(_DATASET, _KIND) - with _Monkey(_implicit_environ, CONNECTION=connection): + + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): iterator = query.fetch() self.assertTrue(iterator._query is query) self.assertEqual(iterator._limit, None) diff --git a/gcloud/datastore/test_transaction.py b/gcloud/datastore/test_transaction.py index c61dfc2e7c1c..9ce9528f0987 100644 --- a/gcloud/datastore/test_transaction.py +++ b/gcloud/datastore/test_transaction.py @@ -29,7 +29,7 @@ def _makeOne(self, dataset_id=None, connection=None): def test_ctor_missing_required(self): from gcloud.datastore import _implicit_environ - self.assertEqual(_implicit_environ.DATASET_ID, None) + self.assertEqual(_implicit_environ.get_default_dataset_id(), None) with self.assertRaises(ValueError): self._makeOne() @@ -55,11 +55,12 @@ def test_ctor_with_env(self): from gcloud._testing import _Monkey from gcloud.datastore import _implicit_environ - DATASET_ID = 'DATASET' CONNECTION = _Connection() + DATASET_ID = 'DATASET' + MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CONNECTION, + DATASET_ID) - with _Monkey(_implicit_environ, DATASET_ID=DATASET_ID, - CONNECTION=CONNECTION): + with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): xact = self._makeOne() self.assertEqual(xact.id, None)