本文整理汇总了Python中backdrop.core.query.Query.create方法的典型用法代码示例。如果您正苦于以下问题:Python Query.create方法的具体用法?Python Query.create怎么用?Python Query.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backdrop.core.query.Query
的用法示例。
在下文中一共展示了Query.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_query_with_time_limits
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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
# 需要导入模块: from backdrop.core.query import Query [as 别名]
# 或者: from backdrop.core.query.Query import create [as 别名]
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_([]))