Example #1
0
    def test_batch(self):
        from google.cloud.datastore import client as MUT
        from google.cloud._testing import _Monkey

        creds = object()
        client = self._makeOne(credentials=creds)

        with _Monkey(MUT, Batch=_Dummy):
            batch = client.batch()

        self.assertIsInstance(batch, _Dummy)
        self.assertEqual(batch.args, (client,))
        self.assertEqual(batch.kwargs, {})
Example #2
0
 def test__push_batch_and__pop_batch(self):
     creds = object()
     client = self._makeOne(credentials=creds)
     batch = client.batch()
     xact = client.transaction()
     client._push_batch(batch)
     self.assertEqual(list(client._batch_stack), [batch])
     self.assertIs(client.current_batch, batch)
     self.assertIsNone(client.current_transaction)
     client._push_batch(xact)
     self.assertIs(client.current_batch, xact)
     self.assertIs(client.current_transaction, xact)
     # list(_LocalStack) returns in reverse order.
     self.assertEqual(list(client._batch_stack), [xact, batch])
     self.assertIs(client._pop_batch(), xact)
     self.assertEqual(list(client._batch_stack), [batch])
     self.assertIs(client._pop_batch(), batch)
     self.assertEqual(list(client._batch_stack), [])