From 611cb6728dcaa1543cb5fe56a812709084fbe8fb Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 6 Jan 2015 15:31:35 -0800 Subject: [PATCH 1/4] Removing Dataset from Transaction and using its components. Also - Making id(), connection() and mutation() getters on Transaction into @property's. - Removing dataset() getter from Transaction. --- gcloud/datastore/connection.py | 8 +++--- gcloud/datastore/test_connection.py | 11 ++++---- gcloud/datastore/test_transaction.py | 40 +++++++++++++++------------- gcloud/datastore/transaction.py | 39 +++++++++++---------------- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index a8bc9880a92b..1d44b6f0e636 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -358,7 +358,7 @@ def commit(self, dataset_id, mutation_pb): if self.transaction(): request.mode = datastore_pb.CommitRequest.TRANSACTIONAL - request.transaction = self.transaction().id() + request.transaction = self.transaction().id else: request.mode = datastore_pb.CommitRequest.NON_TRANSACTIONAL @@ -378,11 +378,11 @@ def rollback(self, dataset_id): :type dataset_id: string :param dataset_id: The dataset to which the transaction belongs. """ - if not self.transaction() or not self.transaction().id(): + if not self.transaction() or not self.transaction().id: raise ValueError('No transaction to rollback.') request = datastore_pb.RollbackRequest() - request.transaction = self.transaction().id() + request.transaction = self.transaction().id # Nothing to do with this response, so just execute the method. self._rpc(dataset_id, 'rollback', request, datastore_pb.RollbackResponse) @@ -549,7 +549,7 @@ def _set_read_options(self, request, eventual): if eventual: opts.read_consistency = datastore_pb.ReadOptions.EVENTUAL elif transaction: - opts.transaction = transaction.id() + opts.transaction = transaction.id def _copy_deferred_keys(lookup_request, lookup_response): diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index bba6371219c3..5c54a2921e8a 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -765,8 +765,8 @@ def test_commit_w_transaction(self): from gcloud.datastore import datastore_v1_pb2 as datastore_pb class Xact(object): - def id(self): - return 'xact' + id = 'xact' + DATASET_ID = 'DATASET' key_pb = self._make_key_pb(DATASET_ID) rsp_pb = datastore_pb.CommitResponse() @@ -808,9 +808,8 @@ def test_rollback_wo_existing_transaction(self): def test_rollback_w_existing_transaction_no_id(self): class Xact(object): + id = None - def id(self): - return None DATASET_ID = 'DATASET' conn = self._makeOne() conn.transaction(Xact()) @@ -823,9 +822,8 @@ def test_rollback_ok(self): TRANSACTION = 'xact' class Xact(object): + id = TRANSACTION - def id(self): - return TRANSACTION rsp_pb = datastore_pb.RollbackResponse() conn = self._makeOne() conn.transaction(Xact()) @@ -1162,6 +1160,7 @@ class Transaction(object): def __init__(self, id): self._id = id + @property def id(self): return self._id diff --git a/gcloud/datastore/test_transaction.py b/gcloud/datastore/test_transaction.py index b48b51208331..3a601b6e7c35 100644 --- a/gcloud/datastore/test_transaction.py +++ b/gcloud/datastore/test_transaction.py @@ -32,20 +32,24 @@ def test_ctor(self): connection = _Connection() dataset = _Dataset(_DATASET, connection) xact = self._makeOne(dataset) - self.assertTrue(xact.dataset() is dataset) - self.assertEqual(xact.id(), None) - self.assertTrue(isinstance(xact.mutation(), Mutation)) + self.assertEqual(xact._dataset_id, _DATASET) + self.assertEqual(xact._connection, connection) + self.assertEqual(xact.id, None) + self.assertTrue(isinstance(xact.mutation, Mutation)) self.assertEqual(len(xact._auto_id_entities), 0) - self.assertTrue(xact.connection() is connection) def test_ctor_with_env(self): - SENTINEL_VAL = object() - from gcloud.datastore import _implicit_environ - _implicit_environ.DATASET = SENTINEL_VAL + + DATASET_ID = 'DATASET' + CONNECTION = _Connection() + DATASET = _Dataset(DATASET_ID, CONNECTION) + + _implicit_environ.DATASET = DATASET transaction = self._makeOne(dataset=None) - self.assertEqual(transaction.dataset(), SENTINEL_VAL) + self.assertEqual(transaction._dataset_id, DATASET_ID) + self.assertEqual(transaction._connection, CONNECTION) def test_add_auto_id_entity(self): entity = _Entity() @@ -62,7 +66,7 @@ def test_begin(self): dataset = _Dataset(_DATASET, connection) xact = self._makeOne(dataset) xact.begin() - self.assertEqual(xact.id(), 234) + self.assertEqual(xact.id, 234) self.assertEqual(connection._begun, _DATASET) self.assertTrue(connection._xact is xact) @@ -73,7 +77,7 @@ def test_rollback(self): xact = self._makeOne(dataset) xact.begin() xact.rollback() - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) self.assertEqual(connection._rolled_back, _DATASET) self.assertEqual(connection._xact, None) @@ -87,7 +91,7 @@ def test_commit_no_auto_ids(self): xact.commit() self.assertEqual(connection._committed, (_DATASET, mutation)) self.assertTrue(connection._xact is None) - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) def test_commit_w_auto_ids(self): _DATASET = 'DATASET' @@ -105,7 +109,7 @@ def test_commit_w_auto_ids(self): xact.commit() self.assertEqual(connection._committed, (_DATASET, mutation)) self.assertTrue(connection._xact is None) - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) self.assertEqual(entity._key._path, [{'kind': _KIND, 'id': _ID}]) def test_commit_w_already(self): @@ -119,7 +123,7 @@ def test_commit_w_already(self): xact.commit() self.assertEqual(connection._committed, None) self.assertTrue(connection._xact is None) - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) def test_context_manager_no_raise(self): _DATASET = 'DATASET' @@ -128,12 +132,12 @@ def test_context_manager_no_raise(self): xact = self._makeOne(dataset) xact._mutation = mutation = object() with xact: - self.assertEqual(xact.id(), 234) + self.assertEqual(xact.id, 234) self.assertEqual(connection._begun, _DATASET) self.assertTrue(connection._xact is xact) self.assertEqual(connection._committed, (_DATASET, mutation)) self.assertTrue(connection._xact is None) - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) def test_context_manager_w_raise(self): class Foo(Exception): @@ -145,17 +149,17 @@ class Foo(Exception): xact._mutation = object() try: with xact: - self.assertEqual(xact.id(), 234) + self.assertEqual(xact.id, 234) self.assertEqual(connection._begun, _DATASET) self.assertTrue(connection._xact is xact) raise Foo() except Foo: - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) self.assertEqual(connection._rolled_back, _DATASET) self.assertEqual(connection._xact, None) self.assertEqual(connection._committed, None) self.assertTrue(connection._xact is None) - self.assertEqual(xact.id(), None) + self.assertEqual(xact.id, None) def _make_key(kind, id, dataset_id): diff --git a/gcloud/datastore/transaction.py b/gcloud/datastore/transaction.py index 663e6acbb2bb..73398000261c 100644 --- a/gcloud/datastore/transaction.py +++ b/gcloud/datastore/transaction.py @@ -18,7 +18,7 @@ from gcloud.datastore import datastore_v1_pb2 as datastore_pb -class Transaction(_implicit_environ._DatastoreBase): +class Transaction(object): """An abstraction representing datastore Transactions. Transactions can be used to build up a bulk mutuation as well as @@ -126,39 +126,32 @@ class Transaction(_implicit_environ._DatastoreBase): """ def __init__(self, dataset=None): - super(Transaction, self).__init__(dataset=dataset) - # If self._dataset is None, using this transaction will fail. + dataset = dataset or _implicit_environ.DATASET + self._connection = dataset.connection() + self._dataset_id = dataset.id() self._id = None self._mutation = datastore_pb.Mutation() self._auto_id_entities = [] + @property def connection(self): """Getter for current connection over which the transaction will run. :rtype: :class:`gcloud.datastore.connection.Connection` :returns: The connection over which the transaction will run. """ + return self._connection - return self.dataset().connection() - - def dataset(self): - """Getter for the current dataset. - - :rtype: :class:`gcloud.datastore.dataset.Dataset` - :returns: The dataset to which the transaction belongs. - """ - - return self._dataset - + @property def id(self): """Getter for the transaction ID. :rtype: string :returns: The ID of the current transaction. """ - return self._id + @property def mutation(self): """Getter for the current mutation. @@ -196,8 +189,8 @@ def begin(self): statement, however it can be called explicitly if you don't want to use a context manager. """ - self._id = self.connection().begin_transaction(self.dataset().id()) - self.connection().transaction(self) + self._id = self.connection.begin_transaction(self._dataset_id) + self.connection.transaction(self) def rollback(self): """Rolls back the current transaction. @@ -207,8 +200,8 @@ def rollback(self): - Sets the current connection's transaction reference to None. - Sets the current transaction's ID to None. """ - self.connection().rollback(self.dataset().id()) - self.connection().transaction(None) + self.connection.rollback(self._dataset_id) + self.connection.transaction(None) self._id = None def commit(self): @@ -226,9 +219,9 @@ def commit(self): """ # It's possible that they called commit() already, in which case # we shouldn't do any committing of our own. - if self.connection().transaction(): - result = self.connection().commit(self.dataset().id(), - self.mutation()) + if self.connection.transaction(): + result = self.connection.commit(self._dataset_id, + self.mutation) # For any of the auto-id entities, make sure we update their keys. for i, entity in enumerate(self._auto_id_entities): @@ -237,7 +230,7 @@ def commit(self): entity.key(entity.key().completed_key(new_id)) # Tell the connection that the transaction is over. - self.connection().transaction(None) + self.connection.transaction(None) # Clear our own ID in case this gets accidentally reused. self._id = None From 2b1c37bd9c433a48a4d6f31a500bab1f50589830 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 6 Jan 2015 16:30:59 -0800 Subject: [PATCH 2/4] Changing Transaction constructor to take dataset ID and connection. Also - Fixed some unfound bugs due to disagreeing code and mocks. - Fixed test pollution of _implicit_environ namespace. --- gcloud/datastore/connection.py | 2 +- gcloud/datastore/test_connection.py | 22 +++------ gcloud/datastore/test_entity.py | 14 ++++-- gcloud/datastore/test_helpers.py | 4 +- gcloud/datastore/test_key.py | 10 ++++ gcloud/datastore/test_transaction.py | 73 ++++++++++++---------------- gcloud/datastore/transaction.py | 24 ++++++--- 7 files changed, 80 insertions(+), 69 deletions(-) diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index 1d44b6f0e636..eeacc44ba35c 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -149,7 +149,7 @@ def mutation(self): (if one exists) or or a new mutation instance. """ if self.transaction(): - return self.transaction().mutation() + return self.transaction().mutation else: return datastore_pb.Mutation() diff --git a/gcloud/datastore/test_connection.py b/gcloud/datastore/test_connection.py index 5c54a2921e8a..2224c121f8cd 100644 --- a/gcloud/datastore/test_connection.py +++ b/gcloud/datastore/test_connection.py @@ -203,8 +203,8 @@ class Mutation(object): pass class Xact(object): - def mutation(self): - return Mutation() + mutation = Mutation() + conn = self._makeOne() conn.transaction(Xact()) found = conn.mutation() @@ -1036,11 +1036,9 @@ def test_save_entity_wo_transaction_w_auto_id(self): def test_save_entity_w_transaction(self): from gcloud.datastore import datastore_v1_pb2 as datastore_pb - mutation = datastore_pb.Mutation() - class Xact(object): - def mutation(self): - return mutation + mutation = datastore_pb.Mutation() + DATASET_ID = 'DATASET' key_pb = self._make_key_pb(DATASET_ID) rsp_pb = datastore_pb.CommitResponse() @@ -1057,11 +1055,9 @@ def test_save_entity_w_transaction_nested_entity(self): from gcloud.datastore import datastore_v1_pb2 as datastore_pb from gcloud.datastore.entity import Entity - mutation = datastore_pb.Mutation() - class Xact(object): - def mutation(self): - return mutation + mutation = datastore_pb.Mutation() + DATASET_ID = 'DATASET' nested = Entity() nested['bar'] = u'Bar' @@ -1112,11 +1108,9 @@ def test_delete_entities_wo_transaction(self): def test_delete_entities_w_transaction(self): from gcloud.datastore import datastore_v1_pb2 as datastore_pb - mutation = datastore_pb.Mutation() - class Xact(object): - def mutation(self): - return mutation + mutation = datastore_pb.Mutation() + DATASET_ID = 'DATASET' key_pb = self._make_key_pb(DATASET_ID) rsp_pb = datastore_pb.CommitResponse() diff --git a/gcloud/datastore/test_entity.py b/gcloud/datastore/test_entity.py index 62afa4f365fe..4a54ce7198be 100644 --- a/gcloud/datastore/test_entity.py +++ b/gcloud/datastore/test_entity.py @@ -21,11 +21,19 @@ class TestEntity(unittest2.TestCase): - def _getTargetClass(self): + def setUp(self): from gcloud.datastore import _implicit_environ - from gcloud.datastore.entity import Entity + self._replaced_dataset = _implicit_environ.DATASET + self._replaced_dataset_id = _implicit_environ.DATASET_ID + _implicit_environ.DATASET = _implicit_environ.DATASET_ID = None + + def tearDown(self): + from gcloud.datastore import _implicit_environ + _implicit_environ.DATASET = self._replaced_dataset + _implicit_environ.DATASET_ID = self._replaced_dataset_id - _implicit_environ.DATASET = None + def _getTargetClass(self): + from gcloud.datastore.entity import Entity return Entity def _makeOne(self, key=None, exclude_from_indexes=()): diff --git a/gcloud/datastore/test_helpers.py b/gcloud/datastore/test_helpers.py index d3fc0243f21e..5809a427f24d 100644 --- a/gcloud/datastore/test_helpers.py +++ b/gcloud/datastore/test_helpers.py @@ -20,11 +20,13 @@ class Test_entity_from_protobuf(unittest2.TestCase): def setUp(self): from gcloud.datastore import _implicit_environ self._replaced_dataset = _implicit_environ.DATASET - _implicit_environ.DATASET = None + self._replaced_dataset_id = _implicit_environ.DATASET_ID + _implicit_environ.DATASET = _implicit_environ.DATASET_ID = None def tearDown(self): from gcloud.datastore import _implicit_environ _implicit_environ.DATASET = self._replaced_dataset + _implicit_environ.DATASET_ID = self._replaced_dataset_id 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 d4c3eceac5f2..beb6fd92ef4a 100644 --- a/gcloud/datastore/test_key.py +++ b/gcloud/datastore/test_key.py @@ -20,6 +20,16 @@ class TestKey(unittest2.TestCase): def setUp(self): self._DEFAULT_DATASET = 'DATASET' + from gcloud.datastore import _implicit_environ + self._replaced_dataset = _implicit_environ.DATASET + self._replaced_dataset_id = _implicit_environ.DATASET_ID + _implicit_environ.DATASET = _implicit_environ.DATASET_ID = None + + def tearDown(self): + from gcloud.datastore import _implicit_environ + _implicit_environ.DATASET = self._replaced_dataset + _implicit_environ.DATASET_ID = self._replaced_dataset_id + def _getTargetClass(self): from gcloud.datastore import _implicit_environ from gcloud.datastore.dataset import Dataset diff --git a/gcloud/datastore/test_transaction.py b/gcloud/datastore/test_transaction.py index 3a601b6e7c35..b1b0f5ee785d 100644 --- a/gcloud/datastore/test_transaction.py +++ b/gcloud/datastore/test_transaction.py @@ -22,16 +22,28 @@ def _getTargetClass(self): return Transaction - def _makeOne(self, dataset=None): - return self._getTargetClass()(dataset) + def _makeOne(self, dataset_id=None, connection=None): + return self._getTargetClass()(dataset_id=dataset_id, + connection=connection) + + def test_ctor_missing_required(self): + from gcloud.datastore import _implicit_environ + + self.assertEqual(_implicit_environ.DATASET, None) + + with self.assertRaises(ValueError): + self._makeOne() + with self.assertRaises(ValueError): + self._makeOne(dataset_id=object()) + with self.assertRaises(ValueError): + self._makeOne(connection=object()) def test_ctor(self): from gcloud.datastore.datastore_v1_pb2 import Mutation _DATASET = 'DATASET' connection = _Connection() - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) self.assertEqual(xact._dataset_id, _DATASET) self.assertEqual(xact._connection, connection) self.assertEqual(xact.id, None) @@ -39,15 +51,16 @@ 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 DATASET_ID = 'DATASET' CONNECTION = _Connection() - DATASET = _Dataset(DATASET_ID, CONNECTION) - _implicit_environ.DATASET = DATASET + with _Monkey(_implicit_environ, DATASET_ID=DATASET_ID, + CONNECTION=CONNECTION): + transaction = self._makeOne() - transaction = self._makeOne(dataset=None) self.assertEqual(transaction._dataset_id, DATASET_ID) self.assertEqual(transaction._connection, CONNECTION) @@ -55,16 +68,14 @@ def test_add_auto_id_entity(self): entity = _Entity() _DATASET = 'DATASET' connection = _Connection() - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact.add_auto_id_entity(entity) self.assertEqual(xact._auto_id_entities, [entity]) def test_begin(self): _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact.begin() self.assertEqual(xact.id, 234) self.assertEqual(connection._begun, _DATASET) @@ -73,8 +84,7 @@ def test_begin(self): def test_rollback(self): _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact.begin() xact.rollback() self.assertEqual(xact.id, None) @@ -84,8 +94,7 @@ def test_rollback(self): def test_commit_no_auto_ids(self): _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact._mutation = mutation = object() xact.begin() xact.commit() @@ -100,8 +109,7 @@ def test_commit_w_auto_ids(self): connection = _Connection(234) connection._commit_result = _CommitResult( _make_key(_KIND, _ID, _DATASET)) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) entity = _Entity() xact.add_auto_id_entity(entity) xact._mutation = mutation = object() @@ -110,13 +118,12 @@ def test_commit_w_auto_ids(self): self.assertEqual(connection._committed, (_DATASET, mutation)) self.assertTrue(connection._xact is None) self.assertEqual(xact.id, None) - self.assertEqual(entity._key._path, [{'kind': _KIND, 'id': _ID}]) + self.assertEqual(entity.key.path, [{'kind': _KIND, 'id': _ID}]) def test_commit_w_already(self): _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact._mutation = object() xact.begin() connection.transaction(()) # Simulate previous commit via false-ish. @@ -128,8 +135,7 @@ def test_commit_w_already(self): def test_context_manager_no_raise(self): _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact._mutation = mutation = object() with xact: self.assertEqual(xact.id, 234) @@ -144,8 +150,7 @@ class Foo(Exception): pass _DATASET = 'DATASET' connection = _Connection(234) - dataset = _Dataset(_DATASET, connection) - xact = self._makeOne(dataset) + xact = self._makeOne(dataset_id=_DATASET, connection=connection) xact._mutation = object() try: with xact: @@ -173,19 +178,6 @@ def _make_key(kind, id, dataset_id): return key -class _Dataset(object): - - def __init__(self, id, connection=None): - self._id = id - self._connection = connection - - def id(self): - return self._id - - def connection(self): - return self._connection - - class _Connection(object): _marker = object() _begun = _rolled_back = _committed = _xact = None @@ -221,9 +213,4 @@ class _Entity(object): def __init__(self): from gcloud.datastore.key import Key - self._key = Key('KIND', dataset_id='DATASET') - - def key(self, key=None): - if key is not None: - self._key = key - return self._key + self.key = Key('KIND', dataset_id='DATASET') diff --git a/gcloud/datastore/transaction.py b/gcloud/datastore/transaction.py index 73398000261c..7fea3f35742a 100644 --- a/gcloud/datastore/transaction.py +++ b/gcloud/datastore/transaction.py @@ -121,14 +121,24 @@ class Transaction(object): ... with dataset2.transaction(): ... dataset2.entity('Thing').save() - :type dataset: :class:`gcloud.datastore.dataset.Dataset` - :param dataset: The dataset to which this :class:`Transaction` belongs. + :type dataset_id: :class:`str`. + :param dataset_id: The ID of the dataset. + + :type connection: :class:`gcloud.datastore.connection.Connection` + :param connection: The connection used to connect to datastore. + + :raises: :class:`ValueError` if either a connection or dataset ID + are not set. """ - def __init__(self, dataset=None): - dataset = dataset or _implicit_environ.DATASET - self._connection = dataset.connection() - self._dataset_id = dataset.id() + def __init__(self, dataset_id=None, connection=None): + self._connection = connection or _implicit_environ.CONNECTION + self._dataset_id = dataset_id or _implicit_environ.DATASET_ID + + if self._connection is None or self._dataset_id is None: + raise ValueError('A transaction must have a connection and ' + 'a dataset ID set.') + self._id = None self._mutation = datastore_pb.Mutation() self._auto_id_entities = [] @@ -227,7 +237,7 @@ def commit(self): for i, entity in enumerate(self._auto_id_entities): key_pb = result.insert_auto_id_key[i] new_id = key_pb.path_element[-1].id - entity.key(entity.key().completed_key(new_id)) + entity.key = entity.key.completed_key(new_id) # Tell the connection that the transaction is over. self.connection.transaction(None) From 0002b87de3bdcfa64a06fb68fd8a63a4cbe3e872 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 7 Jan 2015 09:38:15 -0800 Subject: [PATCH 3/4] Adding Transaction.dataset_id property. --- gcloud/datastore/test_transaction.py | 8 ++++---- gcloud/datastore/transaction.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gcloud/datastore/test_transaction.py b/gcloud/datastore/test_transaction.py index b1b0f5ee785d..985b6e467cf2 100644 --- a/gcloud/datastore/test_transaction.py +++ b/gcloud/datastore/test_transaction.py @@ -44,8 +44,8 @@ def test_ctor(self): _DATASET = 'DATASET' connection = _Connection() xact = self._makeOne(dataset_id=_DATASET, connection=connection) - self.assertEqual(xact._dataset_id, _DATASET) - self.assertEqual(xact._connection, connection) + self.assertEqual(xact.dataset_id, _DATASET) + self.assertEqual(xact.connection, connection) self.assertEqual(xact.id, None) self.assertTrue(isinstance(xact.mutation, Mutation)) self.assertEqual(len(xact._auto_id_entities), 0) @@ -61,8 +61,8 @@ def test_ctor_with_env(self): CONNECTION=CONNECTION): transaction = self._makeOne() - self.assertEqual(transaction._dataset_id, DATASET_ID) - self.assertEqual(transaction._connection, CONNECTION) + self.assertEqual(transaction.dataset_id, DATASET_ID) + self.assertEqual(transaction.connection, CONNECTION) def test_add_auto_id_entity(self): entity = _Entity() diff --git a/gcloud/datastore/transaction.py b/gcloud/datastore/transaction.py index 7fea3f35742a..41e3cc575c59 100644 --- a/gcloud/datastore/transaction.py +++ b/gcloud/datastore/transaction.py @@ -143,9 +143,18 @@ def __init__(self, dataset_id=None, connection=None): self._mutation = datastore_pb.Mutation() self._auto_id_entities = [] + @property + def dataset_id(self): + """Getter for dataset ID in which the transaction will run. + + :rtype: :class:`str` + :returns: The dataset ID in which the transaction will run. + """ + return self._dataset_id + @property def connection(self): - """Getter for current connection over which the transaction will run. + """Getter for connection over which the transaction will run. :rtype: :class:`gcloud.datastore.connection.Connection` :returns: The connection over which the transaction will run. From cea9371177dcb04f0869b6a26b58ca86b5c7ccb7 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 7 Jan 2015 09:45:32 -0800 Subject: [PATCH 4/4] Removing unused _implicit_environ._DatastoreBase class. --- gcloud/datastore/_implicit_environ.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py index 4427ee1aa07f..88d19c15682a 100644 --- a/gcloud/datastore/_implicit_environ.py +++ b/gcloud/datastore/_implicit_environ.py @@ -2,9 +2,6 @@ Acts as a mutable namespace to allow the datastore package to imply the current dataset and connection from the enviroment. - -Also provides a base class for classes in the `datastore` package -which could utilize the implicit enviroment. """ @@ -16,15 +13,3 @@ CONNECTION = None """Module global to allow persistent implied connection from enviroment.""" - - -class _DatastoreBase(object): - """Base for all classes in the datastore package. - - Uses the implicit DATASET object as a default dataset attached - to the instances being created. Stores the dataset passed in - on the protected (i.e. non-public) attribute `_dataset`. - """ - - def __init__(self, dataset=None): - self._dataset = dataset or DATASET