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


Python AerospikeClientMock.query方法代码示例

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


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

示例1: TestAerospikeQueryMock

# 需要导入模块: from AerospikeClientMock import AerospikeClientMock [as 别名]
# 或者: from AerospikeClientMock.AerospikeClientMock import query [as 别名]
class TestAerospikeQueryMock(unittest.TestCase):
    def setUp(self):
        self.asm = AerospikeClientMock()
        self.asm.put(("a", "b", 1), {"a": 1, "b": 1})
        self.asm.put(("a", "b", 2), {"a": 2, "b": 2})
        self.asm.put(("a", "b", 3), {"a": 3, "b": 3})
        self.asm.put(("a", "c", 4), {"a": 4, "b": 4})

    def test_query(self):
        query = self.asm.query('a', 'b')
        query.select('a', 'c')
        self.assertEqual(
            [
                (('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None}),
                (('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
                (('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None}),
            ],
            query.results())

    def test_query_namespace(self):
        query = self.asm.query('a')
        query.select('a', 'b')
        self.assertEqual(
            [
                (('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'b': 1}),
                (('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'b': 2}),
                (('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'b': 3}),
                (('a', 'c', 4), {'gen': 1, 'ttl': 0}, {'a': 4, 'b': 4}),
            ],
            query.results())

    def test_query_callback(self):
        result = []

        def callback(data):
            (key, meta, bins) = data
            result.append((key, meta, bins))

        query = self.asm.query('a', 'b')
        query.select('a', 'c')
        query.foreach(callback)
        self.assertEqual(
            [
                (
                    (('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None}),
                    (('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
                    (('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None}),
                )
            ],
            result)

    def test_query_equals(self):
        query = self.asm.query('a', 'b')
        query.select('a', 'c')
        query.where(AerospikePredicatesMock().equals("a", 1))
        self.assertEqual(
            [(('a', 'b', 1), {'gen': 1, 'ttl': 0}, {'a': 1, 'c': None})],
            query.results())

    def test_query_between(self):
        query = self.asm.query('a', 'b')
        query.select('a', 'c')
        query.where(AerospikePredicatesMock().between("a", 1, 4))
        self.assertEqual(
            [(('a', 'b', 2), {'gen': 1, 'ttl': 0}, {'a': 2, 'c': None}),
             (('a', 'b', 3), {'gen': 1, 'ttl': 0}, {'a': 3, 'c': None})],
            query.results())

    def test_query_contains(self):
        self.asm.put(("a", "l", 1), {"list": [1, 2, 3, 4, 5]})
        self.asm.put(("a", "l", 2), {"list": [1, 3, 4, 5]})
        query = self.asm.query('a', 'l')
        query.select('list')
        query.where(AerospikePredicatesMock().contains("list", list, 2))
        self.assertEqual(
            [(('a', 'l', 1), {'gen': 1, 'ttl': 0}, {'list': [1, 2, 3, 4, 5]})],
            query.results())

    def test_query_range(self):
        self.asm.put(("a", "l", 1), {"list": [1, 2, 3, 4, 5]})
        self.asm.put(("a", "l", 2), {"list": [4, 5]})
        query = self.asm.query('a', 'l')
        query.select('list')
        query.where(AerospikePredicatesMock().range("list", list, 1, 3))
        self.assertEqual(
            [(('a', 'l', 1), {'gen': 1, 'ttl': 0}, {'list': [1, 2, 3, 4, 5]})],
            query.results())
开发者ID:tivvit,项目名称:aerospike-client-mock-python,代码行数:89,代码来源:test_AerospikeQueryMock.py


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