Skip to content

Commit 237b698

Browse files
committed
Adding new tests for tombstone-ing behavior in datastore Batch.
1 parent 5630f7f commit 237b698

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

gcloud/datastore/test_batch.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_ctor(self):
3737
self.assertEqual(batch.connection, connection)
3838
self.assertEqual(batch.namespace, _NAMESPACE)
3939
self.assertTrue(batch._id is None)
40+
self.assertEqual(batch._status, batch._INITIAL)
4041
self.assertTrue(isinstance(batch.mutations, datastore_pb2.Mutation))
4142
self.assertEqual(batch._partial_key_entities, [])
4243

@@ -200,13 +201,39 @@ def test_delete_w_completed_key_w_prefixed_project(self):
200201
mutated_key = _mutated_pb(self, batch.mutations, 'delete')
201202
self.assertEqual(mutated_key, key._key)
202203

204+
def test_begin(self):
205+
_PROJECT = 'PROJECT'
206+
client = _Client(_PROJECT, None)
207+
batch = self._makeOne(client)
208+
self.assertEqual(batch._status, batch._INITIAL)
209+
batch.begin()
210+
self.assertEqual(batch._status, batch._IN_PROGRESS)
211+
212+
def test_begin_fail(self):
213+
_PROJECT = 'PROJECT'
214+
client = _Client(_PROJECT, None)
215+
batch = self._makeOne(client)
216+
batch._status = batch._IN_PROGRESS
217+
with self.assertRaises(ValueError):
218+
batch.begin()
219+
220+
def test_rollback(self):
221+
_PROJECT = 'PROJECT'
222+
client = _Client(_PROJECT, None)
223+
batch = self._makeOne(client)
224+
self.assertEqual(batch._status, batch._INITIAL)
225+
batch.rollback()
226+
self.assertEqual(batch._status, batch._ABORTED)
227+
203228
def test_commit(self):
204229
_PROJECT = 'PROJECT'
205230
connection = _Connection()
206231
client = _Client(_PROJECT, connection)
207232
batch = self._makeOne(client)
208233

234+
self.assertEqual(batch._status, batch._INITIAL)
209235
batch.commit()
236+
self.assertEqual(batch._status, batch._FINISHED)
210237

211238
self.assertEqual(connection._committed,
212239
[(_PROJECT, batch._commit_request, None)])
@@ -222,7 +249,9 @@ def test_commit_w_partial_key_entities(self):
222249
key._id = None
223250
batch._partial_key_entities.append(entity)
224251

252+
self.assertEqual(batch._status, batch._INITIAL)
225253
batch.commit()
254+
self.assertEqual(batch._status, batch._FINISHED)
226255

227256
self.assertEqual(connection._committed,
228257
[(_PROJECT, batch._commit_request, None)])

0 commit comments

Comments
 (0)