From 5e281dd33d09ddcfa16315a2c85595ae170acf2c Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 18 Feb 2015 14:36:34 -0800 Subject: [PATCH] Adding _DEFAULTS stubs in all tests that use it. Introduces - concept of `implicit` for `_DefaultsContainer`. - testing module for datastore for patching Verified all test cases that would accidentally rely on _DEFAULTS implicit behavior by using a custom `_DefaultsContainer` that raises when the instance is implicit. Main delta for the custom properties: diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py index 3afc954..1d38562 100644 --- a/gcloud/datastore/_implicit_environ.py +++ b/gcloud/datastore/_implicit_environ.py @@ -38,9 +38,37 @@ class _DefaultsContainer(object): :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 + class FooError(Exception): + pass + + @property + def dataset_id(self): + if self.implicit: + raise self.FooError + return self._dataset_id + + @dataset_id.setter + def dataset_id(self, value): + if self.implicit: + raise self.FooError + self._dataset_id = value + + @property + def connection(self): + if self.implicit: + raise self.FooError + return self._connection + + @connection.setter + def connection(self, value): + if self.implicit: + raise self.FooError + self._connection = value + + def __init__(self, connection=None, dataset_id=None, implicit=False): + self.implicit = implicit + self._connection = connection + self._dataset_id = dataset_id def app_engine_id(): --- gcloud/datastore/_implicit_environ.py | 5 +- gcloud/datastore/_testing.py | 33 +++++++++ gcloud/datastore/test___init__.py | 20 +++--- gcloud/datastore/test__implicit_environ.py | 28 +++++--- gcloud/datastore/test_api.py | 81 ++++++++++++---------- gcloud/datastore/test_batch.py | 13 ++-- gcloud/datastore/test_entity.py | 10 ++- gcloud/datastore/test_helpers.py | 18 +++-- gcloud/datastore/test_key.py | 16 ++--- gcloud/datastore/test_query.py | 23 +++--- gcloud/datastore/test_transaction.py | 16 +++-- 11 files changed, 158 insertions(+), 105 deletions(-) create mode 100644 gcloud/datastore/_testing.py diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py index 7a00794708ad..f5e9841faa1e 100644 --- a/gcloud/datastore/_implicit_environ.py +++ b/gcloud/datastore/_implicit_environ.py @@ -38,7 +38,8 @@ class _DefaultsContainer(object): :param dataset_id: Persistent implied dataset ID from environment. """ - def __init__(self, connection=None, dataset_id=None): + def __init__(self, connection=None, dataset_id=None, implicit=False): + self.implicit = implicit self.connection = connection self.dataset_id = dataset_id @@ -107,4 +108,4 @@ def get_default_dataset_id(): return _DEFAULTS.dataset_id -_DEFAULTS = _DefaultsContainer() +_DEFAULTS = _DefaultsContainer(implicit=True) diff --git a/gcloud/datastore/_testing.py b/gcloud/datastore/_testing.py new file mode 100644 index 000000000000..8a08a818ff29 --- /dev/null +++ b/gcloud/datastore/_testing.py @@ -0,0 +1,33 @@ +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Shared datastore testing utilities.""" + +from gcloud._testing import _Monkey +from gcloud.datastore import _implicit_environ +from gcloud.datastore._implicit_environ import _DefaultsContainer + + +def _monkey_defaults(*args, **kwargs): + mock_defaults = _DefaultsContainer(*args, **kwargs) + return _Monkey(_implicit_environ, _DEFAULTS=mock_defaults) + + +def _setup_defaults(test_case): + test_case._replaced_defaults = _implicit_environ._DEFAULTS + _implicit_environ._DEFAULTS = _DefaultsContainer() + + +def _tear_down_defaults(test_case): + _implicit_environ._DEFAULTS = test_case._replaced_defaults diff --git a/gcloud/datastore/test___init__.py b/gcloud/datastore/test___init__.py index d983706d3334..f9e3f424cb70 100644 --- a/gcloud/datastore/test___init__.py +++ b/gcloud/datastore/test___init__.py @@ -18,14 +18,12 @@ class Test_set_default_dataset_id(unittest2.TestCase): def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( - None, None) + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) def tearDown(self): - from gcloud.datastore import _implicit_environ - _implicit_environ._DEFAULTS = self._replaced_defaults + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) def _callFUT(self, dataset_id=None): from gcloud.datastore import set_default_dataset_id @@ -276,14 +274,12 @@ def test_set_implicit_three_env_appengine_and_compute(self): class Test_set_default_connection(unittest2.TestCase): def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( - None, None) + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) def tearDown(self): - from gcloud.datastore import _implicit_environ - _implicit_environ._DEFAULTS = self._replaced_defaults + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) def _callFUT(self, connection=None): from gcloud.datastore import set_default_connection diff --git a/gcloud/datastore/test__implicit_environ.py b/gcloud/datastore/test__implicit_environ.py index b7dcd37733de..d276b64808f0 100644 --- a/gcloud/datastore/test__implicit_environ.py +++ b/gcloud/datastore/test__implicit_environ.py @@ -17,6 +17,14 @@ class Test_get_default_connection(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self): from gcloud.datastore._implicit_environ import get_default_connection return get_default_connection() @@ -25,17 +33,23 @@ def test_default(self): self.assertEqual(self._callFUT(), None) def test_preset(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults SENTINEL = object() - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(SENTINEL, None) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=SENTINEL): self.assertEqual(self._callFUT(), SENTINEL) class Test_get_default_dataset_id(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self): from gcloud.datastore._implicit_environ import get_default_dataset_id return get_default_dataset_id() @@ -44,10 +58,8 @@ def test_default(self): self.assertEqual(self._callFUT(), None) def test_preset(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults SENTINEL = object() - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, SENTINEL) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(dataset_id=SENTINEL): self.assertEqual(self._callFUT(), SENTINEL) diff --git a/gcloud/datastore/test_api.py b/gcloud/datastore/test_api.py index a5c0a6a5e335..c090226377ed 100644 --- a/gcloud/datastore/test_api.py +++ b/gcloud/datastore/test_api.py @@ -26,10 +26,8 @@ def _callFUT(self, passed=_MARKER, first_key=None): return _require_dataset_id(dataset_id=passed, first_key=first_key) def _monkey(self, dataset_id): - from gcloud.datastore import _implicit_environ - from gcloud._testing import _Monkey - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, dataset_id) - return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) + from gcloud.datastore._testing import _monkey_defaults + return _monkey_defaults(dataset_id=dataset_id) def test_implicit_unset_wo_keys(self): with self._monkey(None): @@ -121,10 +119,8 @@ def _callFUT(self, passed=_MARKER): return _require_connection(passed) def _monkey(self, connection): - from gcloud.datastore import _implicit_environ - from gcloud._testing import _Monkey - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) - return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) + from gcloud.datastore._testing import _monkey_defaults + return _monkey_defaults(connection=connection) def test_implicit_unset(self): with self._monkey(None): @@ -164,6 +160,14 @@ def test_implicit_set_passed_explicitly(self): class Test_get_function(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self, keys, missing=None, deferred=None, connection=None, dataset_id=None): from gcloud.datastore.api import get @@ -455,10 +459,9 @@ def test_hit_multiple_keys_different_dataset(self): dataset_id=DATASET_ID1) def test_implicit_wo_transaction(self): - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.key import Key from gcloud.datastore.test_connection import _Connection - from gcloud._testing import _Monkey DATASET_ID = 'DATASET' KIND = 'Kind' @@ -473,9 +476,8 @@ def test_implicit_wo_transaction(self): CUSTOM_CONNECTION = _Connection(entity_pb) key = Key(KIND, ID, dataset_id=DATASET_ID) - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, - DATASET_ID) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=CUSTOM_CONNECTION, + dataset_id=DATASET_ID): result, = self._callFUT([key]) expected_called_with = { @@ -566,6 +568,14 @@ def test_max_loops(self): class Test_put_function(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self, entities, connection=None, dataset_id=None): from gcloud.datastore.api import put return put(entities, connection=connection, dataset_id=dataset_id) @@ -668,8 +678,7 @@ def test_existing_batch_w_completed_key(self): self.assertEqual(len(CURR_BATCH.mutation.delete), 0) def test_implicit_connection(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.test_batch import _Connection from gcloud.datastore.test_batch import _Entity from gcloud.datastore.test_batch import _Key @@ -680,8 +689,7 @@ def test_implicit_connection(self): entity = _Entity(foo=u'bar') key = entity.key = _Key(_DATASET) - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=connection): # Set up Batch on stack so we can check it is used. with _NoCommitBatch(_DATASET, connection) as CURR_BATCH: result = self._callFUT([entity]) @@ -700,6 +708,14 @@ def test_implicit_connection(self): class Test_delete_function(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self, keys, connection=None, dataset_id=None): from gcloud.datastore.api import delete return delete(keys, connection=connection, dataset_id=dataset_id) @@ -761,8 +777,7 @@ def test_no_batch(self): self.assertEqual(list(mutation.delete), [key.to_protobuf()]) def test_wo_batch_w_key_different_than_default_dataset_id(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.test_batch import _Connection from gcloud.datastore.test_batch import _Key @@ -772,9 +787,8 @@ def test_wo_batch_w_key_different_than_default_dataset_id(self): connection = _Connection() key = _Key(_DATASET) - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, - _DEFAULT_DATASET) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=connection, + dataset_id=_DEFAULT_DATASET): result = self._callFUT([key]) self.assertEqual(result, None) self.assertEqual(len(connection._committed), 1) @@ -825,8 +839,7 @@ def test_w_existing_transaction(self): self.assertEqual(len(connection._committed), 0) def test_implicit_connection_and_dataset_id(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.test_batch import _Connection from gcloud.datastore.test_batch import _Key @@ -835,9 +848,7 @@ def test_implicit_connection_and_dataset_id(self): connection = _Connection() key = _Key(_DATASET) - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, - _DATASET) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=connection, dataset_id=_DATASET): # Set up Batch on stack so we can check it is used. with _NoCommitBatch(_DATASET, connection) as CURR_BATCH: result = self._callFUT([key]) @@ -875,16 +886,14 @@ def test_w_explicit_connection(self): self.assertEqual(len(CONNECTION._called_key_pbs), NUM_IDS) def test_w_implicit_connection(self): - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.key import Key from gcloud.datastore.test_connection import _Connection - from gcloud._testing import _Monkey CUSTOM_CONNECTION = _Connection() NUM_IDS = 2 - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, - 'DATASET') - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=CUSTOM_CONNECTION, + dataset_id='DATASET'): INCOMPLETE_KEY = Key('KIND') result = self._callFUT(INCOMPLETE_KEY, NUM_IDS) @@ -892,15 +901,13 @@ def test_w_implicit_connection(self): self.assertEqual([key.id for key in result], list(range(NUM_IDS))) def test_with_already_completed_key(self): - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore.key import Key from gcloud.datastore.test_connection import _Connection - from gcloud._testing import _Monkey CUSTOM_CONNECTION = _Connection() - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CUSTOM_CONNECTION, - 'DATASET') - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=CUSTOM_CONNECTION, + dataset_id='DATASET'): 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 a82fad2347be..de86cc23d2ac 100644 --- a/gcloud/datastore/test_batch.py +++ b/gcloud/datastore/test_batch.py @@ -27,11 +27,9 @@ def _makeOne(self, dataset_id=None, connection=None): connection=connection) def test_ctor_missing_required(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, None) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(): self.assertRaises(ValueError, self._makeOne) self.assertRaises(ValueError, self._makeOne, dataset_id=object()) self.assertRaises(ValueError, self._makeOne, connection=object()) @@ -48,15 +46,12 @@ def test_ctor_explicit(self): self.assertEqual(batch._auto_id_entities, []) def test_ctor_implicit(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults from gcloud.datastore._datastore_v1_pb2 import Mutation _DATASET = 'DATASET' CONNECTION = _Connection() - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CONNECTION, - _DATASET) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=CONNECTION, dataset_id=_DATASET): batch = self._makeOne() self.assertEqual(batch.dataset_id, _DATASET) diff --git a/gcloud/datastore/test_entity.py b/gcloud/datastore/test_entity.py index 5ec05d3b670e..268c41ec0c78 100644 --- a/gcloud/datastore/test_entity.py +++ b/gcloud/datastore/test_entity.py @@ -22,14 +22,12 @@ class TestEntity(unittest2.TestCase): def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( - None, None) + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) def tearDown(self): - from gcloud.datastore import _implicit_environ - _implicit_environ._DEFAULTS = self._replaced_defaults + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) def _getTargetClass(self): from gcloud.datastore.entity import Entity diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index 95bdefcb2303..61289adced4b 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -18,14 +18,12 @@ class Test_entity_from_protobuf(unittest2.TestCase): def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( - None, None) + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) def tearDown(self): - from gcloud.datastore import _implicit_environ - _implicit_environ._DEFAULTS = self._replaced_defaults + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) def _callFUT(self, val): from gcloud.datastore.helpers import entity_from_protobuf @@ -150,6 +148,14 @@ def test_nested_entity_no_key(self): class Test_key_from_protobuf(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _callFUT(self, val): from gcloud.datastore.helpers import key_from_protobuf diff --git a/gcloud/datastore/test_key.py b/gcloud/datastore/test_key.py index 36edab88861d..eb68f59b9126 100644 --- a/gcloud/datastore/test_key.py +++ b/gcloud/datastore/test_key.py @@ -20,14 +20,12 @@ class TestKey(unittest2.TestCase): _DEFAULT_DATASET = 'DATASET' def setUp(self): - from gcloud.datastore import _implicit_environ - self._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _implicit_environ._DefaultsContainer( - None, None) + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) def tearDown(self): - from gcloud.datastore import _implicit_environ - _implicit_environ._DEFAULTS = self._replaced_defaults + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) def _getTargetClass(self): from gcloud.datastore.key import Key @@ -37,10 +35,8 @@ def _makeOne(self, *args, **kwargs): return self._getTargetClass()(*args, **kwargs) def _monkeyDatasetID(self, dataset_id=_DEFAULT_DATASET): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, dataset_id) - return _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS) + from gcloud.datastore._testing import _monkey_defaults + return _monkey_defaults(dataset_id=dataset_id) 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 3c7727acb2e1..9704ef485e7d 100644 --- a/gcloud/datastore/test_query.py +++ b/gcloud/datastore/test_query.py @@ -17,6 +17,14 @@ class TestQuery(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _getTargetClass(self): from gcloud.datastore.query import Query return Query @@ -28,12 +36,10 @@ def test_ctor_defaults_wo_implicit_dataset_id(self): self.assertRaises(ValueError, self._makeOne) def test_ctor_defaults_w_implicit_dataset_id(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ - _DATASET = 'DATASET' + from gcloud.datastore._testing import _monkey_defaults - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(None, _DATASET) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + _DATASET = 'DATASET' + with _monkey_defaults(dataset_id=_DATASET): query = self._makeOne() self.assertEqual(query.dataset_id, _DATASET) self.assertEqual(query.kind, None) @@ -315,15 +321,14 @@ def test_fetch_defaults_wo_implicit_connection(self): self.assertRaises(ValueError, query.fetch) def test_fetch_defaults_w_implicit_connection(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults + _DATASET = 'DATASET' _KIND = 'KIND' connection = _Connection() query = self._makeOne(_DATASET, _KIND) - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(connection, None) - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=connection): 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 9ce9528f0987..d678712a80a0 100644 --- a/gcloud/datastore/test_transaction.py +++ b/gcloud/datastore/test_transaction.py @@ -17,6 +17,14 @@ class TestTransaction(unittest2.TestCase): + def setUp(self): + from gcloud.datastore._testing import _setup_defaults + _setup_defaults(self) + + def tearDown(self): + from gcloud.datastore._testing import _tear_down_defaults + _tear_down_defaults(self) + def _getTargetClass(self): from gcloud.datastore.transaction import Transaction @@ -52,15 +60,11 @@ def test_ctor(self): self.assertEqual(len(xact._auto_id_entities), 0) def test_ctor_with_env(self): - from gcloud._testing import _Monkey - from gcloud.datastore import _implicit_environ + from gcloud.datastore._testing import _monkey_defaults CONNECTION = _Connection() DATASET_ID = 'DATASET' - MOCK_DEFAULTS = _implicit_environ._DefaultsContainer(CONNECTION, - DATASET_ID) - - with _Monkey(_implicit_environ, _DEFAULTS=MOCK_DEFAULTS): + with _monkey_defaults(connection=CONNECTION, dataset_id=DATASET_ID): xact = self._makeOne() self.assertEqual(xact.id, None)