def test_get_modules(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git'}], 'module_groups': [ {'module_group_name': 'nova-group', 'modules': ['nova', 'python-novaclient']}]}, test_api.make_records(record_type=['commit'], module=['glance', 'nova'])): response = self.app.get('/api/1.0/modules') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'modules': ['glance'], 'text': 'glance'}, {'id': 'nova', 'modules': ['nova'], 'text': 'nova'}, {'group': True, 'id': 'nova-group', 'text': 'nova-group', 'modules': ['nova', 'python-novaclient']}], modules) response = self.app.get('/api/1.0/modules?module_name=glance') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'modules': ['glance'], 'text': 'glance'}], modules)
def test_get_company(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }, { 'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git' }] }, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT'])): response = self.app.get('/api/1.0/companies/nec?module=glance') company = test_api.load_json(response)['company'] self.assertEqual({'id': 'nec', 'text': 'NEC'}, company) response = self.app.get('/api/1.0/companies/google?module=glance') self.assertEqual(404, response.status_code)
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': { 'openstack': {'id': 'openstack', 'module_group_name': 'openstack', 'modules': ['nova', 'glance'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['nova']), test_api.make_records(record_type=['commit'], loc=[100, 200, 300], module=['glance'])): response = self.app.get('/api/1.0/stats/modules?metric=loc&' 'project_type=all') stats = json.loads(response.data)['stats'] self.assertEqual(2, len(stats)) self.assertEqual(600, stats[0]['metric']) self.assertEqual('glance', stats[0]['id']) self.assertEqual(60, stats[1]['metric']) self.assertEqual('nova', stats[1]['id'])
def test_get_module(self): with test_api.make_runtime_storage( {'repos': [ {'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}], 'module_groups': { 'nova-group': {'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova', 'nova-cli'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), }}, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/modules/nova') module = test_api.load_json(response)['module'] self.assertEqual( {'id': 'nova', 'text': 'nova', 'tag': 'module'}, module) response = self.app.get('/api/1.0/modules/nova-group') module = test_api.load_json(response)['module'] self.assertEqual( {'tag': 'group', 'id': 'nova-group', 'text': 'nova-group'}, module)
def test_user_not_found(self): with test_api.make_runtime_storage( { 'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{ 'company_name': 'NEC', 'end_date': 0 }], 'emails': '*****@*****.**' }, 'repos': [{ 'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git' }], 'module_groups': { 'openstack': { 'module_group_name': 'openstack', 'modules': ['nova'] } } }, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): response = self.app.get('/api/1.0/users/nonexistent') self.assertEqual(404, response.status_code)
def test_releases(self): with test_api.make_runtime_storage( { 'releases': [{ 'release_name': 'prehistory', 'end_date': 1365033600 }, { 'release_name': 'havana', 'end_date': 1381968000 }, { 'release_name': 'icehouse', 'end_date': 1397692800 }], 'project_types': [{ 'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli'] }, { 'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance'] }] }, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/releases') releases = test_api.load_json(response)['data'] self.assertEqual(3, len(releases)) self.assertIn({'id': 'all', 'text': 'All'}, releases) self.assertIn({'id': 'icehouse', 'text': 'Icehouse'}, releases)
def test_users(self): with test_api.make_runtime_storage( {'repos': [ {'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}], 'project_types': [ {'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance']}], 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance')}, 'user:john_doe': {'user_name': 'John Doe'}, 'user:bill_smith': {'user_name': 'Bill Smith'}}, test_api.make_records(record_type=['commit'], module=['nova'], user_id=['john_doe', 'bill_smith'])): response = self.app.get('/api/1.0/users?' 'module=nova&metric=commits') users = test_api.load_json(response)['data'] self.assertEqual(2, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) self.assertIn({'id': 'bill_smith', 'text': 'Bill Smith'}, users)
def test_users(self): with test_api.make_runtime_storage( {'repos': [ {'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}], 'project_types': [ {'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance']}], 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance')}, 'user:john_doe': {'user_name': 'John Doe'}, 'user:bill_smith': {'user_name': 'Bill Smith'}}, test_api.make_records(record_type=['commit'], module=['nova'], user_id=['john_doe', 'bill_smith'])): response = self.app.get('/api/1.0/users?' 'module=nova&metric=commits') users = json.loads(response.data)['data'] self.assertEqual(2, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) self.assertIn({'id': 'bill_smith', 'text': 'Bill Smith'}, users)
def test_get_engineers(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git'}], 'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}, 'user:bill': { 'seq': 1, 'user_id': 'bill', 'user_name': 'Bill Smith', 'companies': [{'company_name': 'IBM', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['nova'], user_id=['john_doe']), test_api.make_records(record_type=['commit'], loc=[100, 200, 300], module=['glance'], user_id=['john_doe']), test_api.make_records(record_type=['review'], primary_key=['0123456789'], module=['glance']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], user_id=['john_doe', 'bill'])): response = self.app.get('/api/1.0/stats/engineers?metric=loc') stats = json.loads(response.data)['stats'] self.assertEqual(1, len(stats)) self.assertEqual(660, stats[0]['metric'])
def test_get_company(self): with test_api.make_runtime_storage( { 'repos': [ {'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git'} ], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli']}, {'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT'])): response = self.app.get('/api/1.0/companies/nec?module=glance') company = test_api.load_json(response)['company'] self.assertEqual({'id': 'nec', 'text': 'NEC'}, company) response = self.app.get('/api/1.0/companies/google?module=glance') self.assertEqual(404, response.status_code)
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', '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' }, module)
def test_get_engineers_extended(self): with test_api.make_runtime_storage( {'repos': [ {'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git'}], 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'module_groups': { 'openstack': {'id': 'openstack', 'module_group_name': 'openstack', 'modules': ['nova', 'glance'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance']}], 'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}, 'user:smith': { 'seq': 1, 'user_id': 'smith', 'user_name': 'Bill Smith', 'companies': [{'company_name': 'IBM', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['nova'], user_id=['john_doe']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], value=[1], type=['Code-Review'], author_name=['John Doe'], user_id=['john_doe']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], author_name=['Bill Smith'], user_id=['smith'])): response = self.app.get('/api/1.0/stats/engineers_extended?' 'project_type=all') stats = json.loads(response.data)['stats'] self.assertEqual(2, len(stats)) self.assertEqual(2, stats[0]['mark']) self.assertEqual('john_doe', stats[0]['id']) self.assertEqual(3, stats[0]['commit']) self.assertEqual(2, stats[0]['1'])
def test_get_engineers_extended(self): with test_api.make_runtime_storage( {'repos': [ {'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git'}], 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'module_groups': { 'openstack': {'id': 'openstack', 'module_group_name': 'openstack', 'modules': ['nova', 'glance'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance']}], 'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}, 'user:smith': { 'seq': 1, 'user_id': 'smith', 'user_name': 'Bill Smith', 'companies': [{'company_name': 'IBM', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['nova'], user_id=['john_doe']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], value=[1], type=['Code-Review'], author_name=['John Doe'], user_id=['john_doe']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], author_name=['Bill Smith'], user_id=['smith'])): response = self.app.get('/api/1.0/stats/engineers_extended?' 'project_type=all') stats = test_api.load_json(response)['stats'] self.assertEqual(2, len(stats)) self.assertEqual(2, stats[0]['mark']) self.assertEqual('john_doe', stats[0]['id']) self.assertEqual(3, stats[0]['commit']) self.assertEqual(2, stats[0]['1'])
def test_release_details(self): with test_api.make_runtime_storage( {'releases': [ {'release_name': 'prehistory', 'end_date': 1365033600}, {'release_name': 'icehouse', 'end_date': 1397692800}]}): response = self.app.get('/api/1.0/releases/icehouse') release = json.loads(response.data)['release'] self.assertEqual({'id': 'icehouse', 'text': 'Icehouse'}, release)
def test_get_module(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }], 'module_groups': { 'nova-group': { 'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova-cli', 'nova'], 'tag': 'group' }, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), } }, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/modules/nova') module = test_api.load_json(response)['module'] self.assertEqual( { 'id': 'nova', 'modules': [{ 'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git' }], 'name': 'Nova', 'tag': 'module' }, module) response = self.app.get('/api/1.0/modules/nova-group') module = test_api.load_json(response)['module'] self.assertEqual( { 'id': 'nova-group', 'modules': [{ 'module_name': 'nova-cli' }, { 'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git' }], 'name': 'Nova-group', 'tag': 'group' }, module)
def test_releases_search(self): with test_api.make_runtime_storage( {'releases': [ {'release_name': 'prehistory', 'end_date': 1365033600}, {'release_name': 'havana', 'end_date': 1381968000}, {'release_name': 'icehouse', 'end_date': 1397692800}]}): response = self.app.get('/api/1.0/releases?query=hav') releases = json.loads(response.data)['releases'] self.assertEqual(1, len(releases)) self.assertIn({'id': 'havana', 'text': 'Havana'}, releases)
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': {'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova', 'nova-cli'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), 'glance': test_api.make_module('glance'), }, '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', 'nova-cli'])): response = self.app.get('/api/1.0/modules?' 'project_type=all&metric=commits') 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, 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&metric=commits') 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, 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&metric=commits') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}], modules, message='Expected modules which name contains query')
def test_get_companies(self): with test_api.make_runtime_storage( { 'repos': [ {'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git'} ], 'project_types': [ {'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance']}], 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'module_groups': { 'openstack': {'module_group_name': 'openstack', 'modules': ['nova', 'glance']}, 'nova': {'module_group_name': 'nova', 'modules': ['nova']}, 'glance': {'module_group_name': 'glance', 'modules': ['glance']}, }}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], company_name=['NEC'])): response = self.app.get('/api/1.0/companies?metric=commits&' 'module=glance') companies = test_api.load_json(response)['data'] self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, {'id': 'nec', 'text': 'NEC'}, {'id': 'ntt', 'text': 'NTT'}], companies) response = self.app.get('/api/1.0/companies?metric=marks&' 'module=glance') companies = test_api.load_json(response)['data'] self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, {'id': 'nec', 'text': 'NEC'}], companies)
def test_user_details(self): with test_api.make_runtime_storage( {'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': '*****@*****.**'}}, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): response = self.app.get('/api/1.0/users/john_doe') user = json.loads(response.data)['user'] self.assertEqual('john_doe', user['user_id'])
def test_get_modules(self): with test_api.make_runtime_storage( { 'repos': [ {'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}, {'module': 'glance', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git'} ], 'module_groups': { 'nova-group': {'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova', 'nova-cli'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), 'glance': test_api.make_module('glance'), }, 'releases': [ {'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], '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', 'nova-cli'])): response = self.app.get('/api/1.0/modules?' 'project_type=all&metric=commits') modules = test_api.load_json(response)['data'] 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, 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&metric=commits') modules = test_api.load_json(response)['data'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}, {'id': 'nova', 'text': 'nova', 'tag': 'module'}, {'id': 'nova-group', 'text': 'nova-group', 'tag': 'group'}], modules, message='Expected modules belonging to project type plus ' 'module groups that are completely within ' 'project type')
def test_releases(self): with test_api.make_runtime_storage( {'releases': [ {'release_name': 'prehistory', 'end_date': 1365033600}, {'release_name': 'havana', 'end_date': 1381968000}, {'release_name': 'icehouse', 'end_date': 1397692800}]}, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/releases') releases = json.loads(response.data)['data'] self.assertEqual(3, len(releases)) self.assertIn({'id': 'all', 'text': 'All'}, releases) self.assertIn({'id': 'icehouse', 'text': 'Icehouse'}, releases)
def test_users_search(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}], 'project_types': [ {'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): response = self.app.get('/api/1.0/users?module=nova&query=doe') users = json.loads(response.data)['users'] self.assertEqual(1, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users)
def test_release_details(self): with test_api.make_runtime_storage({ 'releases': [{ 'release_name': 'prehistory', 'end_date': 1365033600 }, { 'release_name': 'icehouse', 'end_date': 1397692800 }] }): response = self.app.get('/api/1.0/releases/icehouse') release = json.loads(response.data)['release'] self.assertEqual({'id': 'icehouse', 'text': 'Icehouse'}, release)
def test_user_not_found(self): with test_api.make_runtime_storage( {'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': '*****@*****.**'}, 'repos': [{'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}], 'module_groups': {'openstack': { 'module_group_name': 'openstack', 'modules': ['nova']}}}, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): response = self.app.get('/api/1.0/users/nonexistent') self.assertEqual(404, response.status_code)
def test_get_companies(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git'}], 'project_types': [ {'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance']} ], 'module_groups': { 'openstack': {'module_group_name': 'openstack', 'modules': ['nova', 'glance']}, 'nova': {'module_group_name': 'nova', 'modules': ['nova']}, 'glance': {'module_group_name': 'glance', 'modules': ['glance']}, }}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], company_name=['NEC'])): response = self.app.get('/api/1.0/companies?metric=commits&' 'module=glance') companies = json.loads(response.data)['data'] # Commented out for now. Causing CI tests to fail # self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, # {'id': 'nec', 'text': 'NEC'}, # {'id': 'ntt', 'text': 'NTT'}], companies) response = self.app.get('/api/1.0/companies?metric=marks&' 'module=glance') companies = json.loads(response.data)['data']
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', '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', 'nova-cli'])): response = self.app.get('/api/1.0/modules?' 'project_type=all&metric=commits') 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, 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&metric=commits') 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&metric=commits') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}], modules, message='Expected modules which name contains query')
def test_get_engineers(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git'}], 'module_groups': { 'openstack': {'id': 'openstack', 'module_group_name': 'openstack', 'modules': ['nova', 'glance'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance']}], 'user:john_doe': { 'seq': 1, 'user_id': 'john_doe', 'user_name': 'John Doe', 'companies': [{'company_name': 'NEC', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}, 'user:bill': { 'seq': 1, 'user_id': 'bill', 'user_name': 'Bill Smith', 'companies': [{'company_name': 'IBM', 'end_date': 0}], 'emails': ['*****@*****.**'], 'core': []}}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['nova'], user_id=['john_doe']), test_api.make_records(record_type=['commit'], loc=[100, 200, 300], module=['glance'], user_id=['john_doe']), test_api.make_records(record_type=['review'], primary_key=['0123456789'], module=['glance']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], user_id=['john_doe', 'bill'])): response = self.app.get('/api/1.0/stats/engineers?metric=loc&' 'project_type=all') stats = json.loads(response.data)['stats'] self.assertEqual(1, len(stats)) self.assertEqual(660, stats[0]['metric'])
def test_users_search(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}], 'project_types': [ {'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance']}], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance')}}, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): response = self.app.get('/api/1.0/users?' 'module=nova&query=doe&metric=commits') users = json.loads(response.data)['users'] self.assertEqual(1, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users)
def test_releases_search(self): with test_api.make_runtime_storage({ 'releases': [{ 'release_name': 'prehistory', 'end_date': 1365033600 }, { 'release_name': 'havana', 'end_date': 1381968000 }, { 'release_name': 'icehouse', 'end_date': 1397692800 }] }): response = self.app.get('/api/1.0/releases?query=hav') releases = json.loads(response.data)['releases'] self.assertEqual(1, len(releases)) self.assertIn({'id': 'havana', 'text': 'Havana'}, releases)
def test_get_company(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }, { 'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git' }], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance'), }, 'releases': [{ 'release_name': 'prehistory', 'end_date': 1234567890 }, { 'release_name': 'icehouse', 'end_date': 1234567890 }], 'project_types': [{ 'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli'] }, { 'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance'] }] }, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT'])): response = self.app.get('/api/1.0/companies/nec?module=glance') company = test_api.load_json(response)['company'] self.assertEqual({'id': 'nec', 'text': 'NEC'}, company) response = self.app.get('/api/1.0/companies/google?module=glance') self.assertEqual(404, response.status_code)
def test_releases(self): with test_api.make_runtime_storage( {'releases': [ {'release_name': 'prehistory', 'end_date': 1365033600}, {'release_name': 'havana', 'end_date': 1381968000}, {'release_name': 'icehouse', 'end_date': 1397692800}], 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli']}, {'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/releases') releases = test_api.load_json(response)['data'] self.assertEqual(3, len(releases)) self.assertIn({'id': 'all', 'text': 'All'}, releases) self.assertIn({'id': 'icehouse', 'text': 'Icehouse'}, releases)
def test_get_module(self): with test_api.make_runtime_storage( { 'repos': [ {'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git'}], 'module_groups': { 'nova-group': {'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova-cli', 'nova'], 'tag': 'group'}, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), }, 'releases': [{'release_name': 'prehistory', 'end_date': 1234567890}, {'release_name': 'icehouse', 'end_date': 1234567890}], 'project_types': [ {'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli']}, {'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/modules/nova') module = test_api.load_json(response)['module'] self.assertEqual( {'id': 'nova', 'modules': [ {'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git'} ], 'name': 'Nova', 'tag': 'module'}, module) response = self.app.get('/api/1.0/modules/nova-group') module = test_api.load_json(response)['module'] self.assertEqual( {'id': 'nova-group', 'modules': [ {'module_name': 'nova-cli'}, {'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git'} ], 'name': 'Nova-group', 'tag': 'group'}, module)
def test_users(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}], 'project_types': [ {'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance']}], 'module_groups': { 'nova': test_api.make_module('nova'), 'glance': test_api.make_module('glance')}, 'user:john_doe': {'user_name': 'John Doe'}, 'user:bill_smith': {'user_name': 'Bill Smith'}}, test_api.make_records(record_type=['commit'], module=['nova'], user_id=['john_doe', 'bill_smith'])): response = self.app.get('/api/1.0/users?' 'module=nova&metric=commits') users = json.loads(response.data)['data']
def test_releases(self): with test_api.make_runtime_storage( { 'releases': [{ 'release_name': 'prehistory', 'end_date': 1365033600 }, { 'release_name': 'havana', 'end_date': 1381968000 }, { 'release_name': 'icehouse', 'end_date': 1397692800 }] }, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/releases') releases = json.loads(response.data)['data'] self.assertEqual(3, len(releases)) self.assertIn({'id': 'all', 'text': 'All'}, releases) self.assertIn({'id': 'icehouse', 'text': 'Icehouse'}, releases)
def test_get_company(self): with test_api.make_runtime_storage( {'repos': [{'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git'}, {'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git'}]}, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT'])): response = self.app.get('/api/1.0/companies/nec?module=glance') company = json.loads(response.data)['company'] self.assertEqual({'id': 'nec', 'text': 'NEC'}, company) response = self.app.get('/api/1.0/companies/google?module=glance') self.assertEqual(404, response.status_code)
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', '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'}, module)
def test_users(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git' }], 'project_types': [{ 'id': 'openstack', 'title': 'openstack', 'modules': ['nova', 'glance'] }] }, test_api.make_records(record_type=['commit'], module=['nova'], user_id=['john_doe', 'bill_smith'])): response = self.app.get('/api/1.0/users?module=nova') users = json.loads(response.data)['users'] self.assertEqual(2, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) self.assertIn({'id': 'bill_smith', 'text': 'John Doe'}, users)
def test_releases_empty(self): with test_api.make_runtime_storage({}): response = self.app.get('/api/1.0/releases') self.assertEqual(200, response.status_code)
def test_get_companies(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/nova.git' }, { 'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://github.com/openstack/glance.git' }], 'project_types': [{ 'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance'] }], 'module_groups': { 'openstack': { 'module_group_name': 'openstack', 'modules': ['nova', 'glance'] }, 'nova': { 'module_group_name': 'nova', 'modules': ['nova'] }, 'glance': { 'module_group_name': 'glance', 'modules': ['glance'] }, } }, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], company_name=['NEC'])): response = self.app.get('/api/1.0/companies?metric=commits&' 'module=glance') companies = json.loads(response.data)['data'] # Commented out for now. Causing CI tests to fail # self.assertEqual([{'id': 'ibm', 'text': 'IBM'}, # {'id': 'nec', 'text': 'NEC'}, # {'id': 'ntt', 'text': 'NTT'}], companies) response = self.app.get('/api/1.0/companies?metric=marks&' 'module=glance') companies = json.loads(response.data)['data']
def test_users_empty(self): with test_api.make_runtime_storage({}): response = self.app.get('/api/1.0/users') self.assertEqual(200, response.status_code)
def test_get_modules(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }, { 'module': 'glance', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git' }], 'module_groups': { 'nova-group': { 'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova', 'nova-cli'], 'tag': 'group' }, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), 'glance': test_api.make_module('glance'), }, 'releases': [{ 'release_name': 'prehistory', 'end_date': 1234567890 }, { 'release_name': 'icehouse', 'end_date': 1234567890 }], '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', 'nova-cli'])): response = self.app.get('/api/1.0/modules?' 'project_type=all&metric=commits') modules = test_api.load_json(response)['data'] 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, 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&metric=commits') modules = test_api.load_json(response)['data'] self.assertEqual( [{ 'id': 'glance', 'text': 'glance', 'tag': 'module' }, { 'id': 'nova', 'text': 'nova', 'tag': 'module' }, { 'id': 'nova-group', 'text': 'nova-group', 'tag': 'group' }], modules, message='Expected modules belonging to project type plus ' 'module groups that are completely within ' 'project type')
def test_get_module(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }], 'module_groups': { 'nova-group': { 'id': 'nova-group', 'module_group_name': 'nova-group', 'modules': ['nova-cli', 'nova'], 'tag': 'group' }, 'nova': test_api.make_module('nova'), 'nova-cli': test_api.make_module('nova-cli'), }, 'releases': [{ 'release_name': 'prehistory', 'end_date': 1234567890 }, { 'release_name': 'icehouse', 'end_date': 1234567890 }], 'project_types': [{ 'id': 'all', 'title': 'All', 'modules': ['nova', 'glance', 'nova-cli'] }, { 'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance'] }] }, test_api.make_records(record_type=['commit'])): response = self.app.get('/api/1.0/modules/nova') module = test_api.load_json(response)['module'] self.assertEqual( { 'id': 'nova', 'modules': [{ 'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git' }], 'name': 'Nova', 'tag': 'module' }, module) response = self.app.get('/api/1.0/modules/nova-group') module = test_api.load_json(response)['module'] self.assertEqual( { 'id': 'nova-group', 'modules': [{ 'module_name': 'nova-cli' }, { 'module_name': 'nova', 'repo_uri': 'git://git.openstack.org/openstack/nova.git' }], 'name': 'Nova-group', 'tag': 'group' }, module)
def test_get_companies(self): with test_api.make_runtime_storage( { 'repos': [{ 'module': 'nova', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/nova.git' }, { 'module': 'glance', 'project_type': 'openstack', 'organization': 'openstack', 'uri': 'git://git.openstack.org/openstack/glance.git' }], 'project_types': [{ 'id': 'openstack', 'title': 'OpenStack', 'modules': ['nova', 'glance'] }], 'releases': [{ 'release_name': 'prehistory', 'end_date': 1234567890 }, { 'release_name': 'icehouse', 'end_date': 1234567890 }], 'module_groups': { 'openstack': { 'module_group_name': 'openstack', 'modules': ['nova', 'glance'] }, 'nova': { 'module_group_name': 'nova', 'modules': ['nova'] }, 'glance': { 'module_group_name': 'glance', 'modules': ['glance'] }, } }, test_api.make_records(record_type=['commit'], loc=[10, 20, 30], module=['glance'], company_name=['NEC', 'IBM', 'NTT']), test_api.make_records(record_type=['review'], primary_key=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789', '9876543210'], module=['glance'], company_name=['IBM']), test_api.make_records(record_type=['mark'], review_id=['0123456789'], module=['glance'], company_name=['NEC'])): response = self.app.get('/api/1.0/companies?metric=commits&' 'module=glance') companies = test_api.load_json(response)['data'] self.assertEqual([{ 'id': 'ibm', 'text': 'IBM' }, { 'id': 'nec', 'text': 'NEC' }, { 'id': 'ntt', 'text': 'NTT' }], companies) response = self.app.get('/api/1.0/companies?metric=marks&' 'module=glance') companies = test_api.load_json(response)['data'] self.assertEqual([{ 'id': 'ibm', 'text': 'IBM' }, { 'id': 'nec', 'text': 'NEC' }], companies)