Show module groups that are completely within project type

Module group may contain modules that belong to different project types.
Show only those that belong to selected project type completely. Otherwise
user may wonder why the same module group shows different results
depending on selected project type - that may be misleading.

Also added 'unknown' module into project type 'all'. That module
holds all emails that were not assigned to any of known modules

Change-Id: Ie0f54802463d67ba9de7ddb76f58314b05e58e19
This commit is contained in:
Ilya Shakhat 2014-02-17 18:28:36 +04:00
parent 5e463f0943
commit 1c2a92b559
5 changed files with 37 additions and 12 deletions

View File

@ -85,7 +85,7 @@ def init_releases(vault):
def _make_module(module_id, text, modules, tag):
return {'id': module_id, 'text': text,
'modules': modules, 'tag': tag}
'modules': set(modules), 'tag': tag}
def init_module_groups(vault):

View File

@ -266,6 +266,12 @@ def get_modules_json(records):
if tags:
module_ids = set(module_id for module_id in module_ids
if module_id_index[module_id].get('tag') in tags)
# keep only modules that are in project type completely
pts = parameters.get_parameter({}, 'project_type', 'project_types')
if pts:
m = set(vault.resolve_project_types(pts))
module_ids = set(module_id for module_id in module_ids
if module_id_index[module_id]['modules'] <= m)
query = (flask.request.args.get('query') or '').lower()
matched = []
@ -300,7 +306,9 @@ def get_module(module):
module_id_index = vault.get_vault()['module_id_index']
module = module.lower()
if module in module_id_index:
return module_id_index[module]
return {'id': module_id_index[module]['id'],
'text': module_id_index[module]['text'],
'tag': module_id_index[module]['tag']}
flask.abort(404)

View File

@ -6143,7 +6143,7 @@
{
"id": "all",
"title": "All",
"modules": ["openstack", "openstack-infra", "openstack-dev", "stackforge"]
"modules": ["openstack", "openstack-infra", "openstack-dev", "stackforge", "unknown"]
},
{
"id": "openstack",

View File

@ -152,7 +152,7 @@
{
"id": "all",
"title": "All",
"modules": ["openstack", "openstack-infra", "openstack-dev", "stackforge"]
"modules": ["openstack", "openstack-infra", "openstack-dev", "stackforge", "unknown"]
},
{
"id": "openstack",

View File

@ -28,27 +28,45 @@ class TestAPIModules(test_api.TestAPI):
'uri': 'git://github.com/openstack/glance.git'}],
'module_groups': {'nova-group': {
'module_group_name': 'nova-group',
'modules': ['nova', 'python-novaclient']}},
'modules': ['nova', 'nova-cli']}},
'project_types': [
{'id': 'all', 'title': 'All',
'modules': ['nova', 'glance', 'nova-cli']},
{'id': 'integrated', 'title': 'Integrated',
'modules': ['nova', 'glance']}]},
test_api.make_records(record_type=['commit'],
module=['glance', 'nova'])):
module=['glance', 'nova', 'nova-cli'])):
response = self.app.get('/api/1.0/modules?project_type=all')
modules = json.loads(response.data)['modules']
self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'},
{'id': 'nova', 'text': 'nova', 'tag': 'module'},
{'id': 'nova-cli', 'text': 'nova-cli', 'tag': 'module'},
{'id': 'nova-group', 'text': 'nova-group', 'tag': 'group'}],
modules)
modules,
message='Expected modules belonging to project type plus '
'module groups that are completely within '
'project type')
response = self.app.get('/api/1.0/modules?module=nova-group&'
'project_type=integrated')
modules = json.loads(response.data)['modules']
self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'},
{'id': 'nova', 'text': 'nova', 'tag': 'module'}],
modules,
message='Expected modules belonging to project type plus '
'module groups that are completely within '
'project type')
response = self.app.get('/api/1.0/modules?query=glance&'
'project_type=all')
modules = json.loads(response.data)['modules']
self.assertEqual(
[{'id': 'glance', 'text': 'glance', 'tag': 'module'}],
modules)
modules,
message='Expected modules which name contains query')
def test_get_module(self):
with test_api.make_runtime_storage(
@ -62,11 +80,10 @@ class TestAPIModules(test_api.TestAPI):
response = self.app.get('/api/1.0/modules/nova')
module = json.loads(response.data)['module']
self.assertEqual(
{'id': 'nova', 'modules': ['nova'], 'text': 'nova',
'tag': 'module'}, module)
{'id': 'nova', 'text': 'nova', 'tag': 'module'}, module)
response = self.app.get('/api/1.0/modules/nova-group')
module = json.loads(response.data)['module']
self.assertEqual(
{'tag': 'group', 'id': 'nova-group', 'text': 'nova-group',
'modules': ['nova', 'python-novaclient']}, module)
{'tag': 'group', 'id': 'nova-group', 'text': 'nova-group'},
module)