def test_batch(self): from gcloud.datastore import client as MUT from gcloud._testing import _Monkey client = self._makeOne() with _Monkey(MUT, Batch=_Dummy): batch = client.batch() self.assertTrue(isinstance(batch, _Dummy)) self.assertEqual(batch.args, (client,)) self.assertEqual(batch.kwargs, {})
def test__push_batch_and__pop_batch(self): conn = object() client = self._makeOne(connection=conn) batch = client.batch() xact = client.transaction() client._push_batch(batch) self.assertEqual(list(client._batch_stack), [batch]) self.assertTrue(client.current_batch is batch) self.assertTrue(client.current_transaction is None) client._push_batch(xact) self.assertTrue(client.current_batch is xact) self.assertTrue(client.current_transaction is xact) # list(_LocalStack) returns in reverse order. self.assertEqual(list(client._batch_stack), [xact, batch]) self.assertTrue(client._pop_batch() is xact) self.assertEqual(list(client._batch_stack), [batch]) self.assertTrue(client._pop_batch() is batch) self.assertEqual(list(client._batch_stack), [])