예제 #1
0
    def test_get_multi_hit_w_transaction(self):
        from google.cloud.datastore.key import Key

        TXN_ID = '123'
        KIND = 'Kind'
        ID = 1234
        PATH = [{'kind': KIND, 'id': ID}]

        # Make a found entity pb to be returned from mock backend.
        entity_pb = _make_entity_pb(self.PROJECT, KIND, ID, 'foo', 'Foo')

        # Make a connection to return the entity pb.
        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._add_lookup_result([entity_pb])

        key = Key(KIND, ID, project=self.PROJECT)
        txn = client.transaction()
        txn._id = TXN_ID
        result, = client.get_multi([key], transaction=txn)
        new_key = result.key

        # Check the returned value is as expected.
        self.assertIsNot(new_key, key)
        self.assertEqual(new_key.project, self.PROJECT)
        self.assertEqual(new_key.path, PATH)
        self.assertEqual(list(result), ['foo'])
        self.assertEqual(result['foo'], 'Foo')

        cw = client.connection._lookup_cw
        self.assertEqual(len(cw), 1)
        _, _, _, transaction_id = cw[0]
        self.assertEqual(transaction_id, TXN_ID)
예제 #2
0
    def test_transaction_defaults(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, Transaction=_Dummy):
            xact = client.transaction()

        self.assertIsInstance(xact, _Dummy)
        self.assertEqual(xact.args, (client,))
        self.assertEqual(xact.kwargs, {})
예제 #3
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), [])