本文整理汇总了Python中murano.db.catalog.api.package_search函数的典型用法代码示例。如果您正苦于以下问题:Python package_search函数的具体用法?Python package_search怎么用?Python package_search使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了package_search函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_package_search_no_filters
def test_package_search_no_filters(self):
res = api.package_search({}, self.context)
self.assertEqual(0, len(res))
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=False,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
api.package_upload(
self._stub_package(
is_public=False,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
# I can only edit mine pkgs
res = api.package_search({}, self.context)
self.assertEqual(2, len(res))
for pkg in res:
self.assertEqual(self.tenant_id, pkg.owner_id)
# Admin can see everything
res = api.package_search({}, self.context_admin)
self.assertEqual(4, len(res))
示例2: test_pagination_loops_through_names
def test_pagination_loops_through_names(self):
"""Tests that packages with same display name are not skipped
Creates 10 packages with the same display name and iterates
through them, checking that package are not skipped.
"""
for dummy in range(10):
api.package_upload(
self._stub_package(name='test',
fully_qualified_name=str(uuid.uuid4())),
self.tenant_id)
res = api.package_search({}, self.context, limit=4)
self.assertEqual(4, len(res))
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(4, len(res))
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(2, len(res))
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(0, len(res))
示例3: test_pagination_backwards
def test_pagination_backwards(self):
"""Creates 10 packages with unique names and iterates backwards,
checking that package order is correct.
"""
pkgs = []
for dummy in range(10):
package = api.package_upload(
self._stub_package(name=str(uuid.uuid4()), fully_qualified_name=str(uuid.uuid4())), self.tenant_id
)
pkgs.append(package)
# sort pkg ids by pkg name
pkg_ids = [pkg.id for pkg in sorted(pkgs, key=lambda _pkg: _pkg.name)]
res = api.package_search({}, self.context, limit=10)
self.assertEqual(10, len(res))
self.assertEqual(pkg_ids, [r.id for r in res])
marker = res[-1].id
res = api.package_search({"marker": marker, "sort_dir": "desc"}, self.context, limit=5)
self.assertEqual(5, len(res))
self.assertEqual(list(reversed(pkg_ids[4:9])), [r.id for r in res])
marker = res[-1].id
res = api.package_search({"marker": marker, "sort_dir": "desc"}, self.context, limit=5)
self.assertEqual(4, len(res))
self.assertEqual(list(reversed(pkg_ids[0:4])), [r.id for r in res])
marker = res[-1].id
res = api.package_search({"marker": marker, "sort_dir": "desc"}, self.context, limit=5)
self.assertEqual(0, len(res))
示例4: test_pagination
def test_pagination(self):
"""Creates 10 packages with unique names and iterates through them,
checking that package order is correct.
"""
pkgs = []
for dummy in range(10):
package = api.package_upload(self._stub_package(
name=str(uuid.uuid4()),
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
pkgs.append(package)
# sort pkg ids by pkg name
pkg_ids = [pkg.id for pkg in sorted(pkgs, key=lambda _pkg: _pkg.name)]
res = api.package_search({}, self.context, limit=4)
self.assertEqual(4, len(res))
self.assertEqual(pkg_ids[0:4], [r.id for r in res])
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(4, len(res))
self.assertEqual(pkg_ids[4:8], [r.id for r in res])
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(2, len(res))
self.assertEqual(pkg_ids[8:10], [r.id for r in res])
marker = res[-1].id
res = api.package_search({'marker': marker}, self.context, limit=4)
self.assertEqual(0, len(res))
示例5: test_package_search_no_filters_catalog
def test_package_search_no_filters_catalog(self):
res = api.package_search({}, self.context, catalog=True)
self.assertEqual(0, len(res))
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=False,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
api.package_upload(
self._stub_package(
is_public=False,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
# catalog=True should show public + mine
res = api.package_search({}, self.context, catalog=True)
self.assertEqual(3, len(res))
res = api.package_search({}, self.context_admin, catalog=True)
self.assertEqual(3, len(res))
示例6: test_package_search_search
def test_package_search_search(self):
pkg1 = api.package_upload(
self._stub_package(
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
pkg2 = api.package_upload(
self._stub_package(
tags=[],
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search(
{'search': 'tag1'}, self.context)
self.assertEqual(1, len(res))
res = api.package_search(
{'search': pkg1.fully_qualified_name}, self.context)
self.assertEqual(1, len(res))
res = api.package_search(
{'search': pkg2.fully_qualified_name}, self.context)
self.assertEqual(1, len(res))
res = api.package_search(
{'search': 'not_a_valid_uuid'}, self.context)
self.assertEqual(0, len(res))
res = api.package_search(
{'search': 'some text'}, self.context)
self.assertEqual(2, len(res))
示例7: test_package_search_owned
def test_package_search_owned(self):
api.package_upload(self._stub_package(is_public=True, fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(self._stub_package(is_public=True, fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
res = api.package_search({"owned": "true"}, self.context_admin)
self.assertEqual(1, len(res))
res = api.package_search({"owned": "false"}, self.context_admin)
self.assertEqual(2, len(res))
示例8: test_package_search_type
def test_package_search_type(self):
api.package_upload(
self._stub_package(type="Application", fully_qualified_name=str(uuid.uuid4())), self.tenant_id
)
api.package_upload(self._stub_package(type="Library", fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search({"type": "Library"}, self.context)
self.assertEqual(1, len(res))
res = api.package_search({"type": "Application"}, self.context)
self.assertEqual(1, len(res))
示例9: test_package_search_tags
def test_package_search_tags(self):
api.package_upload(self._stub_package(fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(self._stub_package(tags=[], fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search({"tag": ["tag1"]}, self.context)
self.assertEqual(1, len(res))
res = api.package_search({"tag": ["tag2"]}, self.context)
self.assertEqual(1, len(res))
res = api.package_search({"tag": ["tag3"]}, self.context)
self.assertEqual(0, len(res))
示例10: test_package_search_disabled
def test_package_search_disabled(self):
api.package_upload(
self._stub_package(is_public=True, enabled=True, fully_qualified_name=str(uuid.uuid4())), self.tenant_id
)
api.package_upload(
self._stub_package(is_public=True, enabled=False, fully_qualified_name=str(uuid.uuid4())), self.tenant_id
)
res = api.package_search({"include_disabled": "false"}, self.context)
self.assertEqual(1, len(res))
res = api.package_search({"include_disabled": "true"}, self.context)
self.assertEqual(2, len(res))
示例11: test_package_search_owned
def test_package_search_owned(self):
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id_2)
res = api.package_search({'owned': 'true'}, self.context_admin)
self.assertEqual(len(res), 1)
res = api.package_search({'owned': 'false'}, self.context_admin)
self.assertEqual(len(res), 2)
示例12: test_package_search_search
def test_package_search_search(self):
pkg1 = api.package_upload(self._stub_package(fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
pkg2 = api.package_upload(self._stub_package(tags=[], fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search({"search": "tag1"}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search({"search": pkg1.fully_qualified_name}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search({"search": pkg2.fully_qualified_name}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search({"search": "not_a_valid_uuid"}, self.context)
self.assertEqual(len(res), 0)
res = api.package_search({"search": "some text"}, self.context)
self.assertEqual(len(res), 2)
示例13: search
def search(self, req):
def _validate_limit(value):
if value is None:
return
try:
value = int(value)
except ValueError:
msg = _("limit param must be an integer")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
if value <= 0:
msg = _("limit param must be positive")
LOG.error(msg)
raise exc.HTTPBadRequest(explanation=msg)
return value
policy.check("search_packages", req.context)
filters = _get_filters(req.GET.items())
limit = _validate_limit(filters.get('limit'))
if limit is None:
limit = CONF.packages_opts.limit_param_default
limit = min(CONF.packages_opts.api_limit_max, limit)
result = {}
packages = db_api.package_search(filters, req.context, limit)
if len(packages) == limit:
result['next_marker'] = packages[-1].id
result['packages'] = [package.to_dict() for package in packages]
return result
示例14: test_package_search_disabled
def test_package_search_disabled(self):
api.package_upload(
self._stub_package(
is_public=True,
enabled=True,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
is_public=True,
enabled=False,
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search(
{'include_disabled': 'false'}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search(
{'include_disabled': 'true'}, self.context)
self.assertEqual(len(res), 2)
示例15: test_package_search_tags
def test_package_search_tags(self):
api.package_upload(
self._stub_package(
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
api.package_upload(
self._stub_package(
tags=[],
fully_qualified_name=str(uuid.uuid4())), self.tenant_id)
res = api.package_search(
{'tag': ['tag1']}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search(
{'tag': ['tag2']}, self.context)
self.assertEqual(len(res), 1)
res = api.package_search(
{'tag': ['tag3']}, self.context)
self.assertEqual(len(res), 0)