本文整理汇总了Python中backdrop.read.query.Query类的典型用法代码示例。如果您正苦于以下问题:Python Query类的具体用法?Python Query怎么用?Python Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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"]))
开发者ID:roc,项目名称:backdrop,代码行数:7,代码来源:test_read_api.py
示例2: test_multi_grouping_on_non_existent_keys
def test_multi_grouping_on_non_existent_keys(self):
self.setUpPeopleLocationData()
result1 = self.repo.multi_group("wibble", "wobble", Query.create())
result2 = self.repo.multi_group("wibble", "person", Query.create())
result3 = self.repo.multi_group("person", "wibble", Query.create())
assert_that(result1, is_([]))
assert_that(result2, is_([]))
assert_that(result3, is_([]))
开发者ID:pwaller,项目名称:backdrop,代码行数:10,代码来源:test_database_integration.py
示例3: query
def query(bucket_name):
if request.method == 'OPTIONS':
# OPTIONS requests are made by XHR as part of the CORS spec
# if the client uses custom headers
response = app.make_default_options_response()
response.headers['Access-Control-Max-Age'] = '86400'
response.headers['Access-Control-Allow-Headers'] = 'cache-control'
else:
result = validate_request_args(request.args,
raw_queries_allowed(bucket_name))
if not result.is_valid:
return log_error_and_respond(result.message, 400)
bucket = Bucket(db, bucket_name)
try:
result_data = bucket.query(Query.parse(request.args)).data()
except InvalidOperationError:
return log_error_and_respond('invalid collect for that data', 400)
# Taken from flask.helpers.jsonify to add JSONEncoder
# NB. this can be removed once fix #471 works it's way into a release
# https://github.com/mitsuhiko/flask/pull/471
json_data = json.dumps({"data": result_data}, cls=JsonEncoder,
indent=None if request.is_xhr else 2)
response = app.response_class(json_data, mimetype='application/json')
# allow requests from any origin
response.headers['Access-Control-Allow-Origin'] = '*'
return response
开发者ID:jcbashdown,项目名称:backdrop,代码行数:33,代码来源:api.py
示例4: test_group_by_query_with_collect
def test_group_by_query_with_collect(self):
query = Query.create(group_by="name", sort_by=None, limit=None,
collect=["key"])
self.bucket.query(query)
self.mock_repository.group.assert_called_once_with(
"name", query, None, None, ["key"])
开发者ID:jcbashdown,项目名称:backdrop,代码行数:7,代码来源:test_bucket.py
示例5: test_sorted_group_not_enough_args
def test_sorted_group_not_enough_args(self):
self.setup_playing_cards()
self.assertRaises(
InvalidSortError,
self.repo.group,
"suite", Query.create(), sort=["suite"])
开发者ID:pwaller,项目名称:backdrop,代码行数:7,代码来源:test_database_integration.py
示例6: test_sorted_query_not_enough_args
def test_sorted_query_not_enough_args(self):
self.setup_numeric_values()
self.assertRaises(
InvalidSortError,
self.repo.find,
Query.create(), sort=["value"])
开发者ID:pwaller,项目名称:backdrop,代码行数:7,代码来源:test_database_integration.py
示例7: test_query_with_sort
def test_query_with_sort(self):
query = Query.create(sort_by=["keyname", "descending"])
self.bucket.query(query)
self.mock_repository.find.assert_called_with(
query, sort=["keyname", "descending"], limit=None
)
开发者ID:jcbashdown,项目名称:backdrop,代码行数:7,代码来源:test_bucket.py
示例8: test_multi_group_with_collect
def test_multi_group_with_collect(self):
self.setUpPeopleLocationData()
results = self.repo.multi_group(
"place",
"_week_start_at",
Query.create(),
collect=[("person", "set")]
)
assert_that(results, has_item(has_entries({
"place": "Kettering",
"person:set": ["Jack", "John"]
})))
subgroup_matcher = has_item(
has_entries({
"person:set": ["Jack"],
"_count": 1
}))
assert_that(
results,
has_item(
has_entries({
"_subgroup": subgroup_matcher
})
))
开发者ID:pwaller,项目名称:backdrop,代码行数:28,代码来源:test_database_integration.py
示例9: test_sorted_query_nonsense
def test_sorted_query_nonsense(self):
self.setup_numeric_values()
self.assertRaises(
InvalidSortError,
self.repo.find,
Query.create(), sort=["value", "coolness"])
开发者ID:pwaller,项目名称:backdrop,代码行数:7,代码来源:test_database_integration.py
示例10: test_period_group_query_fails_when_weeks_do_not_start_on_monday
def test_period_group_query_fails_when_weeks_do_not_start_on_monday(self):
multi_group_results = [
{
"is": "Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 1), "_count": 1}
]
},
{
"is": "also Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 8), "_count": 1}
]
},
{
"is": "Tuesday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 9), "_count": 1}
]
},
]
self.mock_repository.multi_group.return_value = \
multi_group_results
try:
self.bucket.query(Query.create(period='week', group_by='d')).data()
assert_that(False)
except ValueError as e:
assert_that(str(e), is_(
"Weeks MUST start on Monday but got date: 2013-04-09 00:00:00"
))
开发者ID:jcbashdown,项目名称:backdrop,代码行数:32,代码来源:test_bucket.py
示例11: test_sorted_group_by_query_with_limit
def test_sorted_group_by_query_with_limit(self):
query = Query.create(group_by="name",
sort_by=["name", "ascending"], limit=100)
self.bucket.query(query)
self.mock_repository.group.assert_called_once_with(
"name", query, ["name", "ascending"], 100, [])
开发者ID:jcbashdown,项目名称:backdrop,代码行数:7,代码来源:test_bucket.py
示例12: test_grouping_by_multiple_keys
def test_grouping_by_multiple_keys(self):
self.setUpPeopleLocationData()
results = self.repo.multi_group("person", "place", Query.create())
assert_that(results, has_item({
"person": "Jack",
"_count": 1,
"_group_count": 1,
"_subgroup": [
{"place": "Kettering", "_count": 1}
]
}))
assert_that(results, has_item({
"person": "Jill",
"_count": 1,
"_group_count": 1,
"_subgroup": [
{"place": "Kennington", "_count": 1}
]
}))
assert_that(results, has_item({
"person": "John",
"_count": 3,
"_group_count": 2,
"_subgroup": [
{"place": "Kennington", "_count": 1},
{"place": "Kettering", "_count": 2},
]
}))
开发者ID:pwaller,项目名称:backdrop,代码行数:30,代码来源:test_database_integration.py
示例13: test_group_by_with_period_is_executed
def test_group_by_with_period_is_executed(self, mock_query):
mock_query.return_value = NoneData()
self.app.get(
'/foo?period=week&group_by=stuff'
)
mock_query.assert_called_with(
Query.create(period="week", group_by="stuff"))
开发者ID:jcbashdown,项目名称:backdrop,代码行数:7,代码来源:test_read_api.py
示例14: test_sorted_group_nonsense
def test_sorted_group_nonsense(self):
self.setup_playing_cards()
self.assertRaises(
InvalidSortError,
self.repo.group,
"suite", Query.create(), sort=["suite", "coolness"])
开发者ID:pwaller,项目名称:backdrop,代码行数:7,代码来源:test_database_integration.py
示例15: test_query_with_start_at_and__end_at
def test_query_with_start_at_and__end_at(self):
query = Query.create(end_at=d(2013, 3, 1, 12, 0, 0),
start_at=d(2013, 2, 1, 12, 0, 0))
self.bucket.query(query)
self.mock_repository.find.assert_called_with(query, sort=None,
limit=None)
开发者ID:jcbashdown,项目名称:backdrop,代码行数:7,代码来源:test_bucket.py
示例16: test_period_group_query_fails_when_weeks_do_not_start_on_monday
def test_period_group_query_fails_when_weeks_do_not_start_on_monday(self):
multi_group_results = [
{
"is": "Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 1), "_count": 1}
]
},
{
"is": "also Monday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 8), "_count": 1}
]
},
{
"is": "Tuesday",
"_subgroup": [
{"_week_start_at": d(2013, 4, 9), "_count": 1}
]
},
]
self.mock_repository.multi_group.return_value = \
multi_group_results
query = Query.create(period=WEEK, group_by='d')
assert_raises(ValueError, self.bucket.query, query)
开发者ID:pwaller,项目名称:backdrop,代码行数:27,代码来源:test_bucket.py
示例17: test_sorted_week_and_group_query_with_limit
def test_sorted_week_and_group_query_with_limit(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 7, 0, 0, 0),
"_count": 1
},
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 5
}
]
}
]
query = Query.create(period="week", group_by="some_group",
sort_by=["_count", "descending"], limit=1,
collect=[])
self.bucket.query(query)
self.mock_repository.multi_group.assert_called_with(
"some_group",
"_week_start_at",
query,
sort=["_count", "descending"],
limit=1,
collect=[])
开发者ID:jcbashdown,项目名称:backdrop,代码行数:31,代码来源:test_bucket.py
示例18: test_month_and_group_query_with_start_and_end_at
def test_month_and_group_query_with_start_and_end_at(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_month_start_at": d(2013, 1, 1, 0, 0, 0),
"_count": 1
},
{
"_month_start_at": d(2013, 2, 1, 0, 0, 0),
"_count": 5
}
]
},
{
"some_group": "val2",
"_count": 8,
"_group_count": 2,
"_subgroup": [
{
"_month_start_at": d(2013, 3, 1, 0, 0, 0),
"_count": 2
},
{
"_month_start_at": d(2013, 4, 1, 0, 0, 0),
"_count": 6
},
{
"_month_start_at": d(2013, 7, 1, 0, 0, 0),
"_count": 6
}
]
}
]
query_result = self.bucket.query(Query.create(period=MONTH,
group_by="some_group",
start_at=d(2013, 1, 1),
end_at=d(2013, 4, 2)))
data = query_result.data()
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)})))
开发者ID:pwaller,项目名称:backdrop,代码行数:59,代码来源:test_bucket.py
示例19: test_query_with_limit
def test_query_with_limit(self):
self.mongo_collection.save({"value": 6})
self.mongo_collection.save({"value": 2})
self.mongo_collection.save({"value": 9})
result = self.repo.find(Query.create(), limit=2)
assert_that(result.count(with_limit_and_skip=True), is_(2))
开发者ID:pwaller,项目名称:backdrop,代码行数:8,代码来源:test_database_integration.py
示例20: test_count_of_outer_elements_should_be_added
def test_count_of_outer_elements_should_be_added(self):
self.setUpPeopleLocationData()
results = self.repo.multi_group("_week_start_at", "person", Query.create())
assert_that(results, has_item(has_entry(
"_count", 1
)))
开发者ID:pwaller,项目名称:backdrop,代码行数:8,代码来源:test_database_integration.py
注:本文中的backdrop.read.query.Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论