stackalytics/tests/api/test_modules.py
Ilya Shakhat 34f43995d2 Project type is back to UI to keep compatibility with 0.4
* To keep UI compatibility with version 0.4 project type is returned.
List of project types is configured in default data, every type is
a list of modules or module groups.
* Module groups now have tags to distinguish between different kinds.
Introduced:
  'group' - for user-configured groups,
  'program' - for official programs,
  'project_type' - for types of projects within official programs,
  'organization' - for module groups generated for github organization

Change-Id: I8d5e46e18c7327e8c9d114e0a5eec021305b843e
2014-02-14 19:11:53 +04:00

73 lines
3.2 KiB
Python

# Copyright (c) 2013 Mirantis Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from tests.api import test_api
class TestAPIModules(test_api.TestAPI):
def test_get_modules(self):
with test_api.make_runtime_storage(
{'repos': [{'module': 'nova', 'organization': 'openstack',
'uri': 'git://github.com/openstack/nova.git'},
{'module': 'glance', 'organization': 'openstack',
'uri': 'git://github.com/openstack/glance.git'}],
'module_groups': {'nova-group': {
'module_group_name': 'nova-group',
'modules': ['nova', 'python-novaclient']}},
'project_types': [
{'id': 'all', 'title': 'All',
'modules': ['nova', 'glance']}]},
test_api.make_records(record_type=['commit'],
module=['glance', 'nova'])):
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-group', 'text': 'nova-group', 'tag': 'group'}],
modules)
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)
def test_get_module(self):
with test_api.make_runtime_storage(
{'repos': [{'module': 'nova', 'organization': 'openstack',
'uri': 'git://github.com/openstack/nova.git'}],
'module_groups': {'nova-group': {
'module_group_name': 'nova-group',
'modules': ['nova', 'python-novaclient']}}},
test_api.make_records(record_type=['commit'])):
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)
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)