本文整理汇总了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())