当前位置: 首页>>代码示例>>Python>>正文


Python Key.to_protobuf方法代码示例

本文整理汇总了Python中gcloud.datastore.key.Key.to_protobuf方法的典型用法代码示例。如果您正苦于以下问题:Python Key.to_protobuf方法的具体用法?Python Key.to_protobuf怎么用?Python Key.to_protobuf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gcloud.datastore.key.Key的用法示例。


在下文中一共展示了Key.to_protobuf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_multi_w_deferred_from_backend_but_not_passed

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_get_multi_w_deferred_from_backend_but_not_passed(self):
        from gcloud.datastore._generated import entity_pb2
        from gcloud.datastore.entity import Entity
        from gcloud.datastore.key import Key

        key1 = Key("Kind", project=self.PROJECT)
        key1_pb = key1.to_protobuf()
        key2 = Key("Kind", 2345, project=self.PROJECT)
        key2_pb = key2.to_protobuf()

        entity1_pb = entity_pb2.Entity()
        entity1_pb.key.CopyFrom(key1_pb)
        entity2_pb = entity_pb2.Entity()
        entity2_pb.key.CopyFrom(key2_pb)

        creds = object()
        client = self._makeOne(credentials=creds)
        # mock up two separate requests
        client.connection._add_lookup_result([entity1_pb], deferred=[key2_pb])
        client.connection._add_lookup_result([entity2_pb])

        missing = []
        found = client.get_multi([key1, key2], missing=missing)
        self.assertEqual(len(found), 2)
        self.assertEqual(len(missing), 0)

        # Check the actual contents on the response.
        self.assertTrue(isinstance(found[0], Entity))
        self.assertEqual(found[0].key.path, key1.path)
        self.assertEqual(found[0].key.project, key1.project)

        self.assertTrue(isinstance(found[1], Entity))
        self.assertEqual(found[1].key.path, key2.path)
        self.assertEqual(found[1].key.project, key2.project)

        cw = client.connection._lookup_cw
        self.assertEqual(len(cw), 2)

        ds_id, k_pbs, eventual, tid = cw[0]
        self.assertEqual(ds_id, self.PROJECT)
        self.assertEqual(len(k_pbs), 2)
        self.assertEqual(key1_pb, k_pbs[0])
        self.assertEqual(key2_pb, k_pbs[1])
        self.assertFalse(eventual)
        self.assertTrue(tid is None)

        ds_id, k_pbs, eventual, tid = cw[1]
        self.assertEqual(ds_id, self.PROJECT)
        self.assertEqual(len(k_pbs), 1)
        self.assertEqual(key2_pb, k_pbs[0])
        self.assertFalse(eventual)
        self.assertTrue(tid is None)
开发者ID:VitalLabs,项目名称:gcloud-python,代码行数:54,代码来源:test_client.py

示例2: test_get_multi_miss_w_deferred

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_get_multi_miss_w_deferred(self):
        from gcloud.datastore.key import Key

        key = Key("Kind", 1234, project=self.PROJECT)

        # Set deferred entity on mock connection.
        creds = object()
        client = self._makeOne(credentials=creds)
        client.connection._add_lookup_result(deferred=[key.to_protobuf()])

        deferred = []
        entities = client.get_multi([key], deferred=deferred)
        self.assertEqual(entities, [])
        self.assertEqual([def_key.to_protobuf() for def_key in deferred], [key.to_protobuf()])
开发者ID:VitalLabs,项目名称:gcloud-python,代码行数:16,代码来源:test_client.py

示例3: test_get_entities_miss_w_deferred

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
 def test_get_entities_miss_w_deferred(self):
     from gcloud.datastore.key import Key
     DATASET_ID = 'DATASET'
     KIND = 'Kind'
     ID = 1234
     PATH = [{'kind': KIND, 'id': ID}]
     connection = _Connection()
     dataset = self._makeOne(DATASET_ID, connection)
     key = Key(path=PATH, dataset_id=DATASET_ID)
     connection._deferred = [key.to_protobuf()]
     deferred = []
     entities = dataset.get_entities([key], deferred=deferred)
     self.assertEqual(entities, [])
     self.assertEqual([def_key.to_protobuf() for def_key in deferred],
                      [key.to_protobuf()])
开发者ID:Aharobot,项目名称:gcloud-python,代码行数:17,代码来源:test_dataset.py

示例4: test_get_multi_miss_w_missing

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_get_multi_miss_w_missing(self):
        from gcloud.datastore._generated import entity_pb2
        from gcloud.datastore.key import Key

        KIND = 'Kind'
        ID = 1234

        # Make a missing entity pb to be returned from mock backend.
        missed = entity_pb2.Entity()
        missed.key.partition_id.dataset_id = self.PROJECT
        path_element = missed.key.path_element.add()
        path_element.kind = KIND
        path_element.id = ID

        creds = object()
        client = self._makeOne(credentials=creds)
        # Set missing entity on mock connection.
        client.connection._add_lookup_result(missing=[missed])

        key = Key(KIND, ID, project=self.PROJECT)
        missing = []
        entities = client.get_multi([key], missing=missing)
        self.assertEqual(entities, [])
        self.assertEqual([missed.key.to_protobuf() for missed in missing],
                         [key.to_protobuf()])
开发者ID:117NO,项目名称:gcloud-python,代码行数:27,代码来源:test_client.py

示例5: test_get_multi_miss_w_missing

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_get_multi_miss_w_missing(self):
        from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
        from gcloud.datastore.key import Key
        from gcloud.datastore.test_connection import _Connection

        KIND = 'Kind'
        ID = 1234

        # Make a missing entity pb to be returned from mock backend.
        missed = datastore_pb.Entity()
        missed.key.partition_id.dataset_id = self.DATASET_ID
        path_element = missed.key.path_element.add()
        path_element.kind = KIND
        path_element.id = ID

        # Set missing entity on mock connection.
        connection = _Connection()
        connection._missing = [missed]
        client = self._makeOne(connection=connection)

        key = Key(KIND, ID, dataset_id=self.DATASET_ID)
        missing = []
        entities = client.get_multi([key], missing=missing)
        self.assertEqual(entities, [])
        self.assertEqual([missed.key.to_protobuf() for missed in missing],
                         [key.to_protobuf()])
开发者ID:GrimDerp,项目名称:gcloud-python,代码行数:28,代码来源:test_client.py

示例6: test_get_multi_miss_w_deferred

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_get_multi_miss_w_deferred(self):
        from gcloud.datastore.key import Key
        from gcloud.datastore.test_connection import _Connection

        key = Key('Kind', 1234, dataset_id=self.DATASET_ID)

        # Set deferred entity on mock connection.
        connection = _Connection()
        connection._deferred = [key.to_protobuf()]
        client = self._makeOne(connection=connection)

        deferred = []
        entities = client.get_multi([key], deferred=deferred)
        self.assertEqual(entities, [])
        self.assertEqual([def_key.to_protobuf() for def_key in deferred],
                         [key.to_protobuf()])
开发者ID:GrimDerp,项目名称:gcloud-python,代码行数:18,代码来源:test_client.py

示例7: test_key

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_key(self):
        from gcloud.datastore.key import Key

        key = Key('PATH', 1234, project='PROJECT')
        name, value = self._callFUT(key)
        self.assertEqual(name, 'key_value')
        self.assertEqual(value, key.to_protobuf())
开发者ID:E-LLP,项目名称:gcloud-python,代码行数:9,代码来源:test_helpers.py

示例8: test_miss_w_deferred

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_miss_w_deferred(self):
        from gcloud.datastore.key import Key
        from gcloud.datastore.test_connection import _Connection

        DATASET_ID = 'DATASET'
        key = Key('Kind', 1234, dataset_id=DATASET_ID)

        # Set deferred entity on mock connection.
        connection = _Connection()
        connection._deferred = [key.to_protobuf()]

        deferred = []
        entities = self._callFUT([key], connection=connection,
                                 deferred=deferred, dataset_id=DATASET_ID)
        self.assertEqual(entities, [])
        self.assertEqual([def_key.to_protobuf() for def_key in deferred],
                         [key.to_protobuf()])
开发者ID:blowmage,项目名称:gcloud-python,代码行数:19,代码来源:test_api.py

示例9: test_key

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
 def test_key(self):
     from gcloud.datastore.dataset import Dataset
     from gcloud.datastore.key import Key
     _DATASET = 'DATASET'
     _KIND = 'KIND'
     _ID = 1234
     _PATH = [{'kind': _KIND, 'id': _ID}]
     key = Key(dataset=Dataset(_DATASET), path=_PATH)
     name, value = self._callFUT(key)
     self.assertEqual(name, 'key_value')
     self.assertEqual(value, key.to_protobuf())
开发者ID:kleyow,项目名称:gcloud-python,代码行数:13,代码来源:test_helpers.py

示例10: test_ancestor

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_ancestor(self):
        from gcloud.datastore.key import Key
        from gcloud.datastore._generated import query_pb2

        ancestor = Key('Ancestor', 123, project='PROJECT')
        pb = self._callFUT(_Query(ancestor=ancestor))
        cfilter = pb.filter.composite_filter
        self.assertEqual(cfilter.op, query_pb2.CompositeFilter.AND)
        self.assertEqual(len(cfilter.filters), 1)
        pfilter = cfilter.filters[0].property_filter
        self.assertEqual(pfilter.property.name, '__key__')
        ancestor_pb = ancestor.to_protobuf()
        self.assertEqual(pfilter.value.key_value, ancestor_pb)
开发者ID:E-LLP,项目名称:gcloud-python,代码行数:15,代码来源:test_query.py

示例11: test_key

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_key(self):
        from gcloud.datastore.dataset import Dataset
        from gcloud.datastore.key import Key

        _DATASET = 'DATASET'
        _KIND = 'KIND'
        _ID = 1234
        _PATH = [{'kind': _KIND, 'id': _ID}]
        pb = self._makePB()
        key = Key(dataset=Dataset(_DATASET), path=_PATH)
        self._callFUT(pb, key)
        value = pb.key_value
        self.assertEqual(value, key.to_protobuf())
开发者ID:feczo,项目名称:gcloud-python,代码行数:15,代码来源:test__helpers.py

示例12: test_ancestor

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
 def test_ancestor(self):
     from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
     from gcloud.datastore.key import Key
     from gcloud.datastore.helpers import _prepare_key_for_request
     ancestor = Key('Ancestor', 123, dataset_id='DATASET')
     pb = self._callFUT(_Query(ancestor=ancestor))
     cfilter = pb.filter.composite_filter
     self.assertEqual(cfilter.operator, datastore_pb.CompositeFilter.AND)
     self.assertEqual(len(cfilter.filter), 1)
     pfilter = cfilter.filter[0].property_filter
     self.assertEqual(pfilter.property.name, '__key__')
     ancestor_pb = _prepare_key_for_request(ancestor.to_protobuf())
     self.assertEqual(pfilter.value.key_value, ancestor_pb)
开发者ID:Botanium,项目名称:gcloud-python,代码行数:15,代码来源:test_query.py

示例13: test_ancester_wo_existing_ancestor_query_w_list

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
 def test_ancester_wo_existing_ancestor_query_w_list(self):
     from gcloud.datastore.key import Key
     _KIND = 'KIND'
     _ID = 123
     key = Key(path=[{'kind': _KIND, 'id': _ID}])
     query = self._makeOne()
     after = query.ancestor([_KIND, _ID])
     self.assertFalse(after is query)
     self.assertTrue(isinstance(after, self._getTargetClass()))
     q_pb = after.to_protobuf()
     self.assertEqual(q_pb.filter.composite_filter.operator, 1) # AND
     f_pb, = list(q_pb.filter.composite_filter.filter)
     p_pb = f_pb.property_filter
     self.assertEqual(p_pb.property.name, '__key__')
     self.assertEqual(p_pb.value.key_value, key.to_protobuf())
开发者ID:kleyow,项目名称:gcloud-python,代码行数:17,代码来源:test_query.py

示例14: test_entity_w_key

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_entity_w_key(self):
        from gcloud.datastore.entity import Entity
        from gcloud.datastore.key import Key

        pb = self._makePB()
        key = Key(path=[{'kind': 'KIND', 'id': 123}])
        entity = Entity().key(key)
        entity['foo'] = 'Foo'
        self._callFUT(pb, entity)
        value = pb.entity_value
        self.assertEqual(value.key, key.to_protobuf())
        props = list(value.property)
        self.assertEqual(len(props), 1)
        self.assertEqual(props[0].name, 'foo')
        self.assertEqual(props[0].value.string_value, 'Foo')
开发者ID:feczo,项目名称:gcloud-python,代码行数:17,代码来源:test__helpers.py

示例15: test_miss_wo_dataset_id

# 需要导入模块: from gcloud.datastore.key import Key [as 别名]
# 或者: from gcloud.datastore.key.Key import to_protobuf [as 别名]
    def test_miss_wo_dataset_id(self):
        from gcloud.datastore.key import Key
        from gcloud.datastore.test_connection import _Connection

        DATASET_ID = 'DATASET'
        connection = _Connection()
        key = Key('Kind', 1234, dataset_id=DATASET_ID)
        results = self._callFUT([key], connection=connection)
        self.assertEqual(results, [])
        expected = {
            'dataset_id': DATASET_ID,
            'key_pbs': [key.to_protobuf()],
            'transaction_id': None,
            'eventual': False,
        }
        self.assertEqual(connection._called_with, expected)
开发者ID:blowmage,项目名称:gcloud-python,代码行数:18,代码来源:test_api.py


注:本文中的gcloud.datastore.key.Key.to_protobuf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。