本文整理汇总了Python中warehouse.views.search函数的典型用法代码示例。如果您正苦于以下问题:Python search函数的具体用法?Python search怎么用?Python search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了search函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_without_a_query
def test_without_a_query(self, monkeypatch, page):
params = {}
if page is not None:
params["page"] = page
query = pretend.stub()
request = pretend.stub(
es=pretend.stub(query=lambda: query),
params=params,
)
page_obj = pretend.stub()
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(request) == {
"page": page_obj,
"term": params.get("q"),
"order": params.get("o"),
}
assert page_cls.calls == [
pretend.call(query, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(request)]
开发者ID:demianbrecht,项目名称:warehouse,代码行数:27,代码来源:test_views.py
示例2: test_without_a_query
def test_without_a_query(self, monkeypatch, db_request, page):
params = MultiDict()
if page is not None:
params["page"] = page
db_request.params = params
es_query = pretend.stub()
db_request.es = pretend.stub(query=lambda *a, **kw: es_query)
page_obj = pretend.stub(page_count=(page or 1) + 10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(db_request) == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": [],
"available_filters": [],
}
assert page_cls.calls == [
pretend.call(es_query, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
开发者ID:alex,项目名称:warehouse,代码行数:28,代码来源:test_views.py
示例3: test_with_an_ordering
def test_with_an_ordering(self, monkeypatch, db_request, page):
params = MultiDict({"q": "foo bar", "o": "-created"})
if page is not None:
params["page"] = page
db_request.params = params
sort = pretend.stub()
suggest = pretend.stub(
sort=pretend.call_recorder(lambda *a, **kw: sort),
)
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: suggest),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
page_obj = pretend.stub(page_count=(page or 1) + 10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(db_request) == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": [],
"available_filters": [],
}
assert page_cls.calls == [
pretend.call(sort, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(
"multi_match",
query="foo bar",
fields=[
"name^2", "version", "author", "author_email",
"maintainer", "maintainer_email", "home_page", "license",
"summary", "description", "keywords", "platform",
"download_url",
],
),
]
assert es_query.suggest.calls == [
pretend.call(
name="name_suggestion",
term={"field": "name"},
text="foo bar",
),
]
assert suggest.sort.calls == [
pretend.call("-created")
]
开发者ID:Python-PyBD,项目名称:warehouse,代码行数:58,代码来源:test_views.py
示例4: test_with_an_ordering
def test_with_an_ordering(self, monkeypatch, db_request, page, order,
expected):
params = MultiDict({"q": "foo bar"})
if page is not None:
params["page"] = page
if order is not None:
params["o"] = order
db_request.params = params
sort = pretend.stub()
suggest = pretend.stub(
sort=pretend.call_recorder(lambda *a, **kw: sort),
)
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: suggest),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
page_obj = pretend.stub(page_count=(page or 1) + 10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(db_request) == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": [],
"available_filters": [],
}
assert page_cls.calls == [
pretend.call(
sort if order is not None else suggest,
url_maker=url_maker,
page=page or 1,
),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(
"dis_max",
queries=self._gather_es_queries(params["q"])
)
]
assert es_query.suggest.calls == [
pretend.call(
"name_suggestion",
params["q"],
term={"field": "name"},
),
]
assert suggest.sort.calls == [pretend.call(i) for i in expected]
开发者ID:alex,项目名称:warehouse,代码行数:57,代码来源:test_views.py
示例5: test_raises_400_with_pagenum_type_str
def test_raises_400_with_pagenum_type_str(self, monkeypatch, db_request):
params = MultiDict({"page": "abc"})
db_request.params = params
es_query = pretend.stub()
db_request.es = pretend.stub(query=lambda *a, **kw: es_query)
page_obj = pretend.stub(page_count=10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
with pytest.raises(HTTPBadRequest):
search(db_request)
assert page_cls.calls == []
开发者ID:alex,项目名称:warehouse,代码行数:19,代码来源:test_views.py
示例6: test_raises_404_with_pagenum_too_high
def test_raises_404_with_pagenum_too_high(self, monkeypatch, db_request):
params = MultiDict({"page": 15})
db_request.params = params
es_query = pretend.stub()
db_request.es = pretend.stub(query=lambda *a, **kw: es_query)
page_obj = pretend.stub(page_count=10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
with pytest.raises(HTTPNotFound):
search(db_request)
assert page_cls.calls == [
pretend.call(es_query, url_maker=url_maker, page=15 or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
开发者ID:andrewgross,项目名称:warehouse,代码行数:22,代码来源:test_views.py
示例7: test_returns_503_when_es_unavailable
def test_returns_503_when_es_unavailable(self, monkeypatch, db_request, metrics):
params = MultiDict({"page": 15})
db_request.params = params
es_query = pretend.stub()
db_request.es = pretend.stub(query=lambda *a, **kw: es_query)
def raiser(*args, **kwargs):
raise elasticsearch.ConnectionError()
monkeypatch.setattr(views, "ElasticsearchPage", raiser)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
with pytest.raises(HTTPServiceUnavailable):
search(db_request)
assert url_maker_factory.calls == [pretend.call(db_request)]
assert metrics.increment.calls == [pretend.call("warehouse.views.search.error")]
assert metrics.histogram.calls == []
开发者ID:craig5,项目名称:warehouse,代码行数:22,代码来源:test_views.py
示例8: test_with_a_single_char_query
def test_with_a_single_char_query(self, monkeypatch, db_request, page):
params = MultiDict({"q": "a"})
if page is not None:
params["page"] = page
db_request.params = params
sort = pretend.stub()
suggest = pretend.stub(
sort=pretend.call_recorder(lambda *a, **kw: sort),
)
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: suggest),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
page_obj = pretend.stub(page_count=(page or 1) + 10, item_count=1000)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(db_request) == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": [],
"available_filters": [],
}
assert page_cls.calls == [
pretend.call(suggest, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(
views.gather_es_queries(params["q"])
)
]
assert es_query.suggest.calls == [
pretend.call(
"name_suggestion",
params["q"],
term={"field": "name"},
),
]
assert db_request.registry.datadog.histogram.calls == [
pretend.call('warehouse.views.search.results', 1000)
]
开发者ID:mbacchi,项目名称:warehouse,代码行数:51,代码来源:test_views.py
示例9: test_with_a_query
def test_with_a_query(self, monkeypatch, page):
params = {"q": "foo bar"}
if page is not None:
params["page"] = page
suggest = pretend.stub()
query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: suggest),
)
request = pretend.stub(
es=pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: query),
),
params=params,
)
page_obj = pretend.stub()
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(request) == {
"page": page_obj,
"term": params.get("q"),
"order": params.get("o"),
}
assert page_cls.calls == [
pretend.call(suggest, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(request)]
assert request.es.query.calls == [
pretend.call(
"multi_match",
query="foo bar",
fields=[
"name^2", "version", "author", "author_email",
"maintainer", "maintainer_email", "home_page", "license",
"summary", "description", "keywords", "platform",
"download_url",
],
),
]
assert query.suggest.calls == [
pretend.call(
name="name_suggestion",
term={"field": "name"},
text="foo bar",
),
]
开发者ID:demianbrecht,项目名称:warehouse,代码行数:51,代码来源:test_views.py
示例10: test_with_classifiers
def test_with_classifiers(self, monkeypatch, db_request, page):
params = MultiDict([
("q", "foo bar"),
("c", "foo :: bar"),
("c", "fiz :: buz"),
])
if page is not None:
params["page"] = page
db_request.params = params
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: es_query),
filter=pretend.call_recorder(lambda *a, **kw: es_query),
sort=pretend.call_recorder(lambda *a, **kw: es_query),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
classifier1 = ClassifierFactory.create(classifier="foo :: bar")
classifier2 = ClassifierFactory.create(classifier="foo :: baz")
classifier3 = ClassifierFactory.create(classifier="fiz :: buz")
project = ProjectFactory.create()
release1 = ReleaseFactory.create(project=project)
release1.created = datetime.date(2011, 1, 1)
release1._classifiers.append(classifier1)
release1._classifiers.append(classifier2)
page_obj = pretend.stub(page_count=(page or 1) + 10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
search_view = search(db_request)
assert search_view == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": params.getall("c"),
"available_filters": [
('foo', [
classifier1.classifier,
classifier2.classifier,
])
],
}
assert (
("fiz", [
classifier3.classifier
]) not in search_view["available_filters"]
)
assert page_cls.calls == [
pretend.call(es_query, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(
"dis_max",
queries=self._gather_es_queries(params["q"])
)
]
assert es_query.suggest.calls == [
pretend.call(
"name_suggestion",
params["q"],
term={"field": "name"},
),
]
assert es_query.filter.calls == [
pretend.call('terms', classifiers=['foo :: bar', 'fiz :: buz'])
]
开发者ID:alex,项目名称:warehouse,代码行数:75,代码来源:test_views.py
示例11: test_with_classifiers
def test_with_classifiers(self, monkeypatch, db_request, page):
params = MultiDict([
("q", "foo bar"),
("c", "foo :: bar"),
("c", "fiz :: buz"),
])
if page is not None:
params["page"] = page
db_request.params = params
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: es_query),
filter=pretend.call_recorder(lambda *a, **kw: es_query),
sort=pretend.call_recorder(lambda *a, **kw: es_query),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
classifier1 = ClassifierFactory.create(classifier="foo :: bar")
classifier2 = ClassifierFactory.create(classifier="foo :: baz")
classifier3 = ClassifierFactory.create(classifier="fiz :: buz")
page_obj = pretend.stub(page_count=(page or 1) + 10)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
assert search(db_request) == {
"page": page_obj,
"term": params.get("q", ''),
"order": params.get("o", ''),
"applied_filters": params.getall("c"),
"available_filters": [
('fiz', [classifier3.classifier]),
('foo', [
classifier1.classifier,
classifier2.classifier,
])
],
}
assert page_cls.calls == [
pretend.call(es_query, url_maker=url_maker, page=page or 1),
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(
"multi_match",
query="foo bar",
fields=[
"name^2", "version", "author", "author_email",
"maintainer", "maintainer_email", "home_page", "license",
"summary", "description", "keywords", "platform",
"download_url",
],
),
]
assert es_query.suggest.calls == [
pretend.call(
name="name_suggestion",
term={"field": "name"},
text="foo bar",
),
]
assert es_query.filter.calls == [
pretend.call('terms', classifiers=['foo :: bar', 'fiz :: buz'])
]
开发者ID:Python-PyBD,项目名称:warehouse,代码行数:70,代码来源:test_views.py
示例12: test_with_classifiers
def test_with_classifiers(self, monkeypatch, db_request, metrics, page):
params = MultiDict([("q", "foo bar"), ("c", "foo :: bar"), ("c", "fiz :: buz")])
if page is not None:
params["page"] = page
db_request.params = params
es_query = pretend.stub(
suggest=pretend.call_recorder(lambda *a, **kw: es_query),
filter=pretend.call_recorder(lambda *a, **kw: es_query),
query=pretend.call_recorder(lambda *a, **kw: es_query),
sort=pretend.call_recorder(lambda *a, **kw: es_query),
)
db_request.es = pretend.stub(
query=pretend.call_recorder(lambda *a, **kw: es_query)
)
classifier1 = ClassifierFactory.create(classifier="foo :: bar")
classifier2 = ClassifierFactory.create(classifier="foo :: baz")
classifier3 = ClassifierFactory.create(classifier="fiz :: buz")
project = ProjectFactory.create()
release1 = ReleaseFactory.create(project=project)
release1.created = datetime.date(2011, 1, 1)
release1._classifiers.append(classifier1)
release1._classifiers.append(classifier2)
page_obj = pretend.stub(page_count=(page or 1) + 10, item_count=1000)
page_cls = pretend.call_recorder(lambda *a, **kw: page_obj)
monkeypatch.setattr(views, "ElasticsearchPage", page_cls)
url_maker = pretend.stub()
url_maker_factory = pretend.call_recorder(lambda request: url_maker)
monkeypatch.setattr(views, "paginate_url_factory", url_maker_factory)
search_view = search(db_request)
assert search_view == {
"page": page_obj,
"term": params.get("q", ""),
"order": params.get("o", ""),
"applied_filters": params.getall("c"),
"available_filters": [
{
"foo": {
classifier1.classifier.split(" :: ")[1]: {},
classifier2.classifier.split(" :: ")[1]: {},
}
}
],
}
assert ("fiz", [classifier3.classifier]) not in search_view["available_filters"]
assert page_cls.calls == [
pretend.call(es_query, url_maker=url_maker, page=page or 1)
]
assert url_maker_factory.calls == [pretend.call(db_request)]
assert db_request.es.query.calls == [
pretend.call(views.gather_es_queries(params["q"]))
]
assert es_query.suggest.calls == [
pretend.call("name_suggestion", params["q"], term={"field": "name"})
]
assert es_query.query.calls == [
pretend.call("prefix", classifiers="foo :: bar"),
pretend.call("prefix", classifiers="fiz :: buz"),
]
assert metrics.histogram.calls == [
pretend.call("warehouse.views.search.results", 1000)
]
开发者ID:craig5,项目名称:warehouse,代码行数:67,代码来源:test_views.py
注:本文中的warehouse.views.search函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论