Added review and mark test data generators
Change-Id: Idfb43d1e86854a4f2a4ab868aeaec57ce9fd97bd
This commit is contained in:
@@ -47,14 +47,19 @@ def make_runtime_storage(data, *generators):
|
|||||||
|
|
||||||
|
|
||||||
def make_records(**kwargs):
|
def make_records(**kwargs):
|
||||||
|
GENERATORS = {
|
||||||
|
'commit': _generate_commits,
|
||||||
|
'mark': _generate_marks,
|
||||||
|
'review': _generate_review,
|
||||||
|
}
|
||||||
|
|
||||||
def generate_records():
|
def generate_records():
|
||||||
record_types = kwargs.get('record_type', [])
|
for record_type in kwargs.get('record_type', []):
|
||||||
if 'commit' in record_types:
|
if record_type in GENERATORS.keys():
|
||||||
for commit in _generate_commits(algebraic_product(**kwargs)):
|
for values in algebraic_product(**kwargs):
|
||||||
yield commit
|
record = GENERATORS[record_type]().next()
|
||||||
elif 'mark' in record_types:
|
record.update(values)
|
||||||
for mark in _generate_marks(algebraic_product(**kwargs)):
|
yield record
|
||||||
yield mark
|
|
||||||
|
|
||||||
return generate_records
|
return generate_records
|
||||||
|
|
||||||
@@ -82,8 +87,7 @@ class TestStorage(runtime_storage.RuntimeStorage):
|
|||||||
yield record
|
yield record
|
||||||
|
|
||||||
|
|
||||||
def _generate_commits(values_list):
|
def _generate_commits():
|
||||||
for values in values_list:
|
|
||||||
commit = {
|
commit = {
|
||||||
'commit_id': str(uuid.uuid4()),
|
'commit_id': str(uuid.uuid4()),
|
||||||
'lines_added': 9, 'module': 'nova', 'record_type': 'commit',
|
'lines_added': 9, 'module': 'nova', 'record_type': 'commit',
|
||||||
@@ -101,33 +105,42 @@ def _generate_commits(values_list):
|
|||||||
'change_id': u'I33f0f37b6460dc494abf2520dc109c9893ace9e6',
|
'change_id': u'I33f0f37b6460dc494abf2520dc109c9893ace9e6',
|
||||||
'release': u'icehouse'
|
'release': u'icehouse'
|
||||||
}
|
}
|
||||||
commit.update(values)
|
|
||||||
yield commit
|
yield commit
|
||||||
|
|
||||||
|
|
||||||
def _generate_marks(values_list):
|
def _generate_marks():
|
||||||
for values in values_list:
|
|
||||||
mark = {
|
mark = {
|
||||||
'record_type': 'mark',
|
'launchpad_id': 'john_doe', 'week': 2294, 'user_id': 'john_doe',
|
||||||
'id': str(uuid.uuid4()),
|
'description': 'Approved', 'author_name': 'John Doe',
|
||||||
'module': 'nova',
|
'author_email': 'john_doe@gmail.com',
|
||||||
'message': str(uuid.uuid4()),
|
'primary_key': str(uuid.uuid4()) + 'APRV',
|
||||||
'subject': 'Fixed affiliation of Edgar and Sumit',
|
'module': 'glance', 'patch': 2, 'record_type': 'mark',
|
||||||
'user_id': 'john_doe',
|
'company_name': '*independent', 'branch': 'master',
|
||||||
'primary_key': str(uuid.uuid4()),
|
'date': 1387860458, 'record_id': 37184, 'release': 'icehouse',
|
||||||
'author_email': 'john_doe@ibm.com', 'company_name': 'IBM',
|
'value': 1, 'type': 'APRV',
|
||||||
'week': 2275,
|
'review_id': str(uuid.uuid4())}
|
||||||
'blueprint_id': None, 'bug_id': '1212953',
|
|
||||||
'author_name': 'John Doe',
|
|
||||||
'date': 1376737923, 'launchpad_id': 'john_doe',
|
|
||||||
'branches': set(['master']),
|
|
||||||
'change_id': 'I33f0f37b6460dc494abf2520dc109c9893ace9e6',
|
|
||||||
'release': 'icehouse'
|
|
||||||
}
|
|
||||||
mark.update(values)
|
|
||||||
yield mark
|
yield mark
|
||||||
|
|
||||||
|
|
||||||
|
def _generate_review():
|
||||||
|
yield {
|
||||||
|
'status': 'NEW', 'review_number': 6, 'number': '60721',
|
||||||
|
'module': 'glance', 'topic': 'bug/1258999', 'record_type': 'review',
|
||||||
|
'value': -2, 'open': True,
|
||||||
|
'id': str(uuid.uuid4()),
|
||||||
|
'subject': 'Adding missing copy_from policy from policy.json',
|
||||||
|
'user_id': 'john_doe',
|
||||||
|
'primary_key': 'Ibc0d1fa7626629c28c514514a985a6b89db2ac69',
|
||||||
|
'author_email': 'john_doe@gmail.com', 'company_name': '*independent',
|
||||||
|
'branch': 'master',
|
||||||
|
'launchpad_id': 'john_doe', 'lastUpdated': 1387865203,
|
||||||
|
'author_name': 'John Doe', 'date': 1386547707,
|
||||||
|
'url': 'https://review.openstack.org/60721', 'patch_count': 2,
|
||||||
|
'sortKey': '0029f92e0000ed31', 'project': 'openstack/glance',
|
||||||
|
'week': 2292, 'release': 'icehouse', 'updated_on': 1387865147
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _add_generated_records(data, *generators):
|
def _add_generated_records(data, *generators):
|
||||||
count = 0
|
count = 0
|
||||||
for gen in generators:
|
for gen in generators:
|
||||||
|
@@ -30,14 +30,14 @@ class TestAPIStats(test_api.TestAPI):
|
|||||||
'uri': 'git://github.com/openstack/glance.git'}]},
|
'uri': 'git://github.com/openstack/glance.git'}]},
|
||||||
test_api.make_records(record_type=['commit'],
|
test_api.make_records(record_type=['commit'],
|
||||||
loc=[10, 20, 30],
|
loc=[10, 20, 30],
|
||||||
module=['nova', 'glance']),
|
module=['nova']),
|
||||||
test_api.make_records(record_type=['commit'],
|
test_api.make_records(record_type=['commit'],
|
||||||
loc=[100, 200, 300],
|
loc=[100, 200, 300],
|
||||||
module=['glance'])):
|
module=['glance'])):
|
||||||
response = self.app.get('/api/1.0/stats/modules?metric=loc')
|
response = self.app.get('/api/1.0/stats/modules?metric=loc')
|
||||||
stats = json.loads(response.data)['stats']
|
stats = json.loads(response.data)['stats']
|
||||||
self.assertEqual(2, len(stats))
|
self.assertEqual(2, len(stats))
|
||||||
self.assertEqual(660, stats[0]['metric'])
|
self.assertEqual(600, stats[0]['metric'])
|
||||||
self.assertEqual('glance', stats[0]['id'])
|
self.assertEqual('glance', stats[0]['id'])
|
||||||
self.assertEqual(60, stats[1]['metric'])
|
self.assertEqual(60, stats[1]['metric'])
|
||||||
self.assertEqual('nova', stats[1]['id'])
|
self.assertEqual('nova', stats[1]['id'])
|
||||||
|
Reference in New Issue
Block a user