本文整理汇总了Python中backdrop.core.query.Query类的典型用法代码示例。如果您正苦于以下问题:Python Query类的具体用法?Python Query怎么用?Python Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_query_with_time_limits
def test_basic_query_with_time_limits(self):
self._save_all('foo_bar',
{'_timestamp': d_tz(2012, 12, 12)},
{'_timestamp': d_tz(2012, 12, 14)},
{'_timestamp': d_tz(2012, 12, 11)})
# start at
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2012, 12, 12, 13)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 14))))
# end at
results = self.engine.execute_query('foo_bar', Query.create(
end_at=d_tz(2012, 12, 11, 13)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 11))))
# both
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2012, 12, 11, 12),
end_at=d_tz(2012, 12, 12, 12)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 12))))
示例2: test_empty_a_data_set
def test_empty_a_data_set(self):
self._save_all('foo_bar',
{'foo': 'bar'}, {'bar': 'foo'})
assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(2))
# TODO: fix inconsistency
self.engine.empty_data_set('foo_bar')
assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(0))
示例3: step
def step(context, amount, key, time):
time_query = parser.parse(time)
if key == '_start_at':
query = Query.create(start_at=time_query, period=DAY, duration=1)
elif key == '_end_at':
query = Query.create(end_at=time_query, period=DAY, duration=-1)
elif key == '_week_start_at':
query = Query.create(start_at=time_query, period=WEEK, duration=1)
else:
raise NotImplementedError(key)
result = context.client.storage().execute_query(context.data_set, query)
assert_that(result, has_length(1))
assert_that(result[0]['_count'], equal_to(int(amount)))
示例4: test_sort_query_is_executed
def test_sort_query_is_executed(self, mock_query):
mock_query.return_value = NoneData()
self.app.get(
'/foo?sort_by=value:ascending'
)
mock_query.assert_called_with(
Query.create(sort_by=["value", "ascending"]))
self.app.get(
'/foo?sort_by=value:descending'
)
mock_query.assert_called_with(
Query.create(sort_by=["value", "descending"]))
示例5: test_basic_query_with_inclusive_time_limits
def test_basic_query_with_inclusive_time_limits(self):
self._save_all('foo_bar',
{'_timestamp': d_tz(2014, 12, 01)},
{'_timestamp': d_tz(2014, 12, 02)},
{'_timestamp': d_tz(2014, 12, 03)})
# start at
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2014, 12, 01),
end_at=d_tz(2014, 12, 03),
inclusive=True))
assert_that(len(results), is_(3))
示例6: test_month_and_group_query_with_start_and_end_at
def test_month_and_group_query_with_start_and_end_at(self):
self.mock_storage.execute_query.return_value = [
{'some_group': 'val1', '_month_start_at': d(2013, 1, 1), '_count': 1},
{'some_group': 'val1', '_month_start_at': d(2013, 2, 1), '_count': 5},
{'some_group': 'val2', '_month_start_at': d(2013, 3, 1), '_count': 2},
{'some_group': 'val2', '_month_start_at': d(2013, 4, 1), '_count': 6},
{'some_group': 'val2', '_month_start_at': d(2013, 7, 1), '_count': 6},
]
data = self.data_set.execute_query(
Query.create(period=MONTH,
group_by=['some_group'],
start_at=d(2013, 1, 1),
end_at=d(2013, 4, 2)))
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
first_group = data[0]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 3, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 4, 1)})))
first_group = data[1]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 1, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 2, 1)})))
示例7: test_period_group_query_adds_missing_periods_in_correct_order
def test_period_group_query_adds_missing_periods_in_correct_order(self):
self.mock_storage.execute_query.return_value = [
{'some_group': 'val1', '_week_start_at': d(2013, 1, 14), '_count': 23},
{'some_group': 'val1', '_week_start_at': d(2013, 1, 21), '_count': 41},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 14), '_count': 31},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 28), '_count': 12},
]
data = self.data_set.execute_query(
Query.create(period=WEEK, group_by=['some_group'],
start_at=d_tz(2013, 1, 7, 0, 0, 0),
end_at=d_tz(2013, 2, 4, 0, 0, 0)))
assert_that(data, has_item(has_entries({
"some_group": "val1",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
),
})))
assert_that(data, has_item(has_entries({
"some_group": "val2",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
),
})))
示例8: test_no_end_at_means_now
def test_no_end_at_means_now(self):
query = Query.create(
period=Day(),
duration=3,
)
assert_that(query.end_at, is_(
datetime(2014, 1, 9, 0, 0, 0, tzinfo=pytz.UTC)))
示例9: test_period_queries_get_sorted_by__week_start_at
def test_period_queries_get_sorted_by__week_start_at(self):
self.setup__timestamp_data()
query = Query.create(period=WEEK)
result = self.data_set.execute_query(query)
assert_that(result, contains(
has_entry('_start_at', d_tz(2012, 12, 31)),
has_entry('_start_at', d_tz(2013, 1, 28)),
has_entry('_start_at', d_tz(2013, 2, 25))
))
示例10: test_datetimes_are_returned_as_utc
def test_datetimes_are_returned_as_utc(self):
self._save_all('foo_bar',
{'_timestamp': datetime.datetime(2012, 8, 8)})
results = self.engine.execute_query('foo_bar', Query.create())
assert_that(results,
contains(
has_entries({'_timestamp': d_tz(2012, 8, 8)})))
示例11: test_capped_data_set_is_capped
def test_capped_data_set_is_capped(self):
self.engine.create_data_set('foo_bar', 1)
for i in range(100):
self.engine.save_record('foo_bar', {'foo': i})
assert_that(
len(self.engine.execute_query('foo_bar', Query.create())),
less_than(70))
示例12: test_query_with_filter_prefix
def test_query_with_filter_prefix(self):
self._save_all('foo_bar', {'foo': 'bar'}, {'foo': 'foo'})
results = self.engine.execute_query('foo_bar', Query.create(
filter_by_prefix=[['foo', 'ba']]))
assert_that(results,
contains(
has_entry('foo', 'bar')))
示例13: test_saving_a_record_with_an_id_updates_it
def test_saving_a_record_with_an_id_updates_it(self):
self._save_all('foo_bar',
{'_id': 'first', 'foo': 'bar'},
{'_id': 'first', 'foo': 'foo'})
results = self.engine.execute_query('foo_bar', Query.create())
assert_that(len(results), is_(1))
assert_that(results, contains(has_entries({'foo': 'foo'})))
示例14: data_set_contains
def data_set_contains(context, data_set_name, sequence_matcher):
documents = [json.loads(line) for line in context.text.split("\n")]
matchers = [has_entries(doc) for doc in documents]
data_set = context.client.storage().execute_query(data_set_name, Query.create())
records = [datetimes_to_strings(record) for record in data_set.find()]
records = [ints_to_floats(record) for record in records]
records = [nones_to_zeroes(record) for record in records]
assert_that(records, sequence_matcher(*matchers))
示例15: test_delete_record
def test_delete_record(self):
data = [{'_id': '111', 'foo': 'bar'}, {'_id': '222', 'bar': 'foo'}]
self._save_all('foo_bar', *data)
assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(2))
self.engine.delete_record('foo_bar', '111')
assert_that(
self.engine.execute_query('foo_bar', Query.create()),
contains(has_entries({'_id': '222', 'bar': 'foo'}))
)
self.engine.delete_record('foo_bar', '333')
assert_that(
self.engine.execute_query('foo_bar', Query.create()),
contains(has_entries({'_id': '222', 'bar': 'foo'}))
)
self.engine.delete_record('foo_bar', '222')
assert_that(self.engine.execute_query('foo_bar', Query.create()), is_([]))