Add an option to filter packages by 'id' in API
This patch enhances the GET /catalog/packages Murano API call with option to filter packages by id. Partially implements bp assign-category-button Change-Id: I86bbdbde74a7fa086197adef7a91199704811f72
This commit is contained in:
parent
88952c40d2
commit
ac9b85e1f5
@ -42,7 +42,7 @@ Methods for application package management
|
|||||||
List packages
|
List packages
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
`/v1/catalog/packages?{marker}{limit}{order_by}{type}{category}{fqn}{owned}{catalog}{class_name} [GET]`
|
`/v1/catalog/packages?{marker}{limit}{order_by}{type}{category}{fqn}{owned}{id}{catalog}{class_name} [GET]`
|
||||||
|
|
||||||
This is the compound request to list and search through application catalog.
|
This is the compound request to list and search through application catalog.
|
||||||
If there are no search parameters all packages that is_public, enabled and belong to the user's tenant will be listed.
|
If there are no search parameters all packages that is_public, enabled and belong to the user's tenant will be listed.
|
||||||
@ -73,6 +73,8 @@ For an admin role all packages are available.
|
|||||||
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``owned`` | bool | Search only from packages owned by current tenant |
|
| ``owned`` | bool | Search only from packages owned by current tenant |
|
||||||
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
||||||
|
| ``id`` | string | Allows to point an id for a search | |
|
||||||
|
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``include_disabled`` | bool | Include disabled packages in a the result |
|
| ``include_disabled`` | bool | Include disabled packages in a the result |
|
||||||
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
+----------------------+-------------+------------------------------------------------------------------------------------------------------------------------------+
|
||||||
| ``search`` | string | Gives opportunity to search specified data by all the package parameters |
|
| ``search`` | string | Gives opportunity to search specified data by all the package parameters |
|
||||||
|
@ -17,10 +17,10 @@ from murano.db import session as db_session
|
|||||||
|
|
||||||
stats = None
|
stats = None
|
||||||
|
|
||||||
SUPPORTED_PARAMS = ('order_by', 'category', 'marker', 'tag', 'class_name',
|
SUPPORTED_PARAMS = ('id', 'order_by', 'category', 'marker', 'tag',
|
||||||
'limit', 'type', 'fqn', 'category', 'owned', 'search',
|
'class_name', 'limit', 'type', 'fqn', 'category', 'owned',
|
||||||
'include_disabled', 'sort_dir')
|
'search', 'include_disabled', 'sort_dir')
|
||||||
LIST_PARAMS = ('category', 'tag', 'class', 'order_by')
|
LIST_PARAMS = ('id', 'category', 'tag', 'class', 'order_by')
|
||||||
ORDER_VALUES = ('fqn', 'name', 'created')
|
ORDER_VALUES = ('fqn', 'name', 'created')
|
||||||
PKG_PARAMS_MAP = {'display_name': 'name',
|
PKG_PARAMS_MAP = {'display_name': 'name',
|
||||||
'full_name': 'fully_qualified_name',
|
'full_name': 'fully_qualified_name',
|
||||||
|
@ -264,6 +264,7 @@ def package_search(filters, context, manage_public=False,
|
|||||||
request and then to use the ID of the last package from the response
|
request and then to use the ID of the last package from the response
|
||||||
as the marker parameter in a subsequent limited request.
|
as the marker parameter in a subsequent limited request.
|
||||||
"""
|
"""
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
|
|
||||||
session = db_session.get_session()
|
session = db_session.get_session()
|
||||||
pkg = models.Package
|
pkg = models.Package
|
||||||
@ -293,6 +294,8 @@ def package_search(filters, context, manage_public=False,
|
|||||||
if 'type' in filters.keys():
|
if 'type' in filters.keys():
|
||||||
query = query.filter(pkg.type == filters['type'].title())
|
query = query.filter(pkg.type == filters['type'].title())
|
||||||
|
|
||||||
|
if 'id' in filters:
|
||||||
|
query = query.filter(models.Package.id.in_(filters['id']))
|
||||||
if 'category' in filters.keys():
|
if 'category' in filters.keys():
|
||||||
query = query.filter(pkg.categories.any(
|
query = query.filter(pkg.categories.any(
|
||||||
models.Category.name.in_(filters['category'])))
|
models.Category.name.in_(filters['category'])))
|
||||||
|
@ -162,6 +162,41 @@ class TestCatalogApi(test_base.ControllerTest, test_base.MuranoApiTestCase):
|
|||||||
'/v1/catalog/packages/', params={'catalog': 'False'}))
|
'/v1/catalog/packages/', params={'catalog': 'False'}))
|
||||||
self.assertEqual(2, len(result['packages']))
|
self.assertEqual(2, len(result['packages']))
|
||||||
|
|
||||||
|
def test_packages_filter_by_id(self):
|
||||||
|
"""GET /catalog/packages with parameter "id" returns packages
|
||||||
|
filtered by id.
|
||||||
|
"""
|
||||||
|
self._set_policy_rules(
|
||||||
|
{'get_package': '',
|
||||||
|
'manage_public_package': ''}
|
||||||
|
)
|
||||||
|
_, package1_data = self._test_package()
|
||||||
|
_, package2_data = self._test_package()
|
||||||
|
|
||||||
|
package1_data['fully_qualified_name'] += '_1'
|
||||||
|
package1_data['name'] += '_1'
|
||||||
|
package1_data['class_definitions'] = (u'test.mpl.v1.app.Thing1',)
|
||||||
|
package2_data['fully_qualified_name'] += '_2'
|
||||||
|
package2_data['name'] += '_2'
|
||||||
|
package2_data['class_definitions'] = (u'test.mpl.v1.app.Thing2',)
|
||||||
|
|
||||||
|
expected_package = db_catalog_api.package_upload(package1_data, '')
|
||||||
|
db_catalog_api.package_upload(package2_data, '')
|
||||||
|
|
||||||
|
req = self._get('/catalog/packages',
|
||||||
|
params={'id': expected_package.id})
|
||||||
|
self.expect_policy_check('get_package')
|
||||||
|
self.expect_policy_check('manage_public_package')
|
||||||
|
|
||||||
|
res = req.get_response(self.api)
|
||||||
|
self.assertEqual(200, res.status_code)
|
||||||
|
|
||||||
|
self.assertEqual(len(res.json['packages']), 1)
|
||||||
|
|
||||||
|
found_package = res.json['packages'][0]
|
||||||
|
|
||||||
|
self.assertEqual(found_package['id'], expected_package.id)
|
||||||
|
|
||||||
def test_packages(self):
|
def test_packages(self):
|
||||||
self._set_policy_rules(
|
self._set_policy_rules(
|
||||||
{'get_package': '',
|
{'get_package': '',
|
||||||
|
Loading…
Reference in New Issue
Block a user