예제 #1
0
    def test_put_multi_no_batch_w_partial_key(self):
        from gcloud.datastore.helpers import _property_tuples
        from gcloud.datastore.test_batch import _Entity
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _KeyPB
        from gcloud.datastore.test_batch import _mutated_pb

        entity = _Entity(foo=u"bar")
        key = entity.key = _Key(self.PROJECT)
        key._id = None

        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._commit.append([_KeyPB(key)])

        result = client.put_multi([entity])
        self.assertTrue(result is None)

        self.assertEqual(len(client.connection._commit_cw), 1)
        (project, commit_req, transaction_id) = client.connection._commit_cw[0]
        self.assertEqual(project, self.PROJECT)

        mutated_entity = _mutated_pb(self, commit_req.mutations, "insert")
        self.assertEqual(mutated_entity.key, key.to_protobuf())

        prop_list = list(_property_tuples(mutated_entity))
        self.assertTrue(len(prop_list), 1)
        name, value_pb = prop_list[0]
        self.assertEqual(name, "foo")
        self.assertEqual(value_pb.string_value, u"bar")

        self.assertTrue(transaction_id is None)
예제 #2
0
    def test_put_multi_no_batch_w_partial_key(self):
        from gcloud.datastore.helpers import _property_tuples
        from gcloud.datastore.test_batch import _Entity
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _KeyPB
        from gcloud.datastore.test_batch import _mutated_pb

        entity = _Entity(foo=u'bar')
        key = entity.key = _Key(self.PROJECT)
        key._id = None

        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._commit.append([_KeyPB(key)])

        result = client.put_multi([entity])
        self.assertTrue(result is None)

        self.assertEqual(len(client.connection._commit_cw), 1)
        (project, commit_req, transaction_id) = client.connection._commit_cw[0]
        self.assertEqual(project, self.PROJECT)

        mutated_entity = _mutated_pb(self, commit_req.mutations, 'insert')
        self.assertEqual(mutated_entity.key, key.to_protobuf())

        prop_list = list(_property_tuples(mutated_entity))
        self.assertTrue(len(prop_list), 1)
        name, value_pb = prop_list[0]
        self.assertEqual(name, 'foo')
        self.assertEqual(value_pb.string_value, u'bar')

        self.assertTrue(transaction_id is None)
예제 #3
0
    def test_delete_multi_w_existing_transaction(self):
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        creds = object()
        client = self._makeOne(credentials=creds)
        key = _Key(self.PROJECT)

        with _NoCommitTransaction(client) as CURR_XACT:
            result = client.delete_multi([key])

        self.assertEqual(result, None)
        mutated_key = _mutated_pb(self, CURR_XACT.mutations, 'delete')
        self.assertEqual(mutated_key, key._key)
        self.assertEqual(len(client.connection._commit_cw), 0)
예제 #4
0
    def test_delete_multi_w_existing_transaction(self):
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        creds = object()
        client = self._makeOne(credentials=creds)
        key = _Key(self.PROJECT)

        with _NoCommitTransaction(client) as CURR_XACT:
            result = client.delete_multi([key])

        self.assertEqual(result, None)
        mutated_key = _mutated_pb(self, CURR_XACT.mutations, "delete")
        self.assertEqual(mutated_key, key._key)
        self.assertEqual(len(client.connection._commit_cw), 0)
예제 #5
0
    def test_delete_multi_w_existing_batch(self):
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        creds = object()
        client = self._makeOne(credentials=creds)
        key = _Key(self.DATASET_ID)

        with _NoCommitBatch(client) as CURR_BATCH:
            result = client.delete_multi([key])

        self.assertEqual(result, None)
        mutated_key = _mutated_pb(self, CURR_BATCH.mutations, 'delete')
        self.assertEqual(mutated_key, key._key)
        self.assertEqual(len(client.connection._commit_cw), 0)
예제 #6
0
    def test_delete_multi_no_batch(self):
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        key = _Key(self.PROJECT)

        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._commit.append([])

        result = client.delete_multi([key])
        self.assertEqual(result, None)
        self.assertEqual(len(client.connection._commit_cw), 1)
        (project, commit_req, transaction_id) = client.connection._commit_cw[0]
        self.assertEqual(project, self.PROJECT)

        mutated_key = _mutated_pb(self, commit_req.mutations, "delete")
        self.assertEqual(mutated_key, key.to_protobuf())
        self.assertTrue(transaction_id is None)
예제 #7
0
    def test_delete_multi_no_batch(self):
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        key = _Key(self.PROJECT)

        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._commit.append([])

        result = client.delete_multi([key])
        self.assertEqual(result, None)
        self.assertEqual(len(client.connection._commit_cw), 1)
        (project, commit_req, transaction_id) = client.connection._commit_cw[0]
        self.assertEqual(project, self.PROJECT)

        mutated_key = _mutated_pb(self, commit_req.mutations, 'delete')
        self.assertEqual(mutated_key, key.to_protobuf())
        self.assertTrue(transaction_id is None)
예제 #8
0
    def test_put_multi_existing_batch_w_completed_key(self):
        from gcloud.datastore.helpers import _property_tuples
        from gcloud.datastore.test_batch import _Entity
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        creds = object()
        client = self._makeOne(credentials=creds)
        entity = _Entity(foo=u'bar')
        key = entity.key = _Key(self.PROJECT)

        with _NoCommitBatch(client) as CURR_BATCH:
            result = client.put_multi([entity])

        self.assertEqual(result, None)
        mutated_entity = _mutated_pb(self, CURR_BATCH.mutations, 'upsert')
        self.assertEqual(mutated_entity.key, key.to_protobuf())

        prop_list = list(_property_tuples(mutated_entity))
        self.assertTrue(len(prop_list), 1)
        name, value_pb = prop_list[0]
        self.assertEqual(name, 'foo')
        self.assertEqual(value_pb.string_value, u'bar')
예제 #9
0
    def test_put_multi_existing_batch_w_completed_key(self):
        from gcloud.datastore.helpers import _property_tuples
        from gcloud.datastore.test_batch import _Entity
        from gcloud.datastore.test_batch import _Key
        from gcloud.datastore.test_batch import _mutated_pb

        creds = object()
        client = self._makeOne(credentials=creds)
        entity = _Entity(foo=u"bar")
        key = entity.key = _Key(self.PROJECT)

        with _NoCommitBatch(client) as CURR_BATCH:
            result = client.put_multi([entity])

        self.assertEqual(result, None)
        mutated_entity = _mutated_pb(self, CURR_BATCH.mutations, "upsert")
        self.assertEqual(mutated_entity.key, key.to_protobuf())

        prop_list = list(_property_tuples(mutated_entity))
        self.assertTrue(len(prop_list), 1)
        name, value_pb = prop_list[0]
        self.assertEqual(name, "foo")
        self.assertEqual(value_pb.string_value, u"bar")