def __init__(self, client, read_only=False):
     super(Transaction, self).__init__(client)
     self._id = None
     if read_only:
         options = TransactionOptions(read_only=TransactionOptions.ReadOnly())
     else:
         options = TransactionOptions()
     self._options = options
Exemplo n.º 2
0
 def test_read_only_transaction_defaults(self):
     from google.cloud.datastore_v1.types import TransactionOptions
     creds = _make_credentials()
     client = self._make_one(credentials=creds)
     xact = client.transaction(read_only=True)
     self.assertEqual(
         xact._options,
         TransactionOptions(read_only=TransactionOptions.ReadOnly()))
     self.assertFalse(xact._options.HasField("read_write"))
     self.assertTrue(xact._options.HasField("read_only"))
     self.assertEqual(xact._options.read_only,
                      TransactionOptions.ReadOnly())
Exemplo n.º 3
0
    def test_begin_transaction_w_options(self):
        from google.cloud.datastore_v1.types import TransactionOptions

        read_only = TransactionOptions.ReadOnly._meta.pb()
        options = TransactionOptions(read_only=read_only)
        self._begin_transaction_helper(options=options)