Make initialization of test runtime storage easier
Change-Id: I6016ad3c304278017aece80b7bcc97ff0f4300cb
This commit is contained in:
@@ -31,15 +31,9 @@ class TestAPI(testtools.TestCase):
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def make_runtime_storage(data, record_type=None, **kwargs):
|
||||
|
||||
if record_type:
|
||||
count = 0
|
||||
for record in generate_records(record_type, **kwargs):
|
||||
record['record_id'] = count
|
||||
data['record:%s' % count] = record
|
||||
count += 1
|
||||
data['record:count'] = count
|
||||
def make_runtime_storage(data, *args):
|
||||
for arg in args:
|
||||
data.update(arg)
|
||||
|
||||
runtime_storage_inst = TestStorage(data)
|
||||
setattr(web.app, 'stackalytics_vault', None)
|
||||
@@ -76,8 +70,8 @@ class TestStorage(runtime_storage.RuntimeStorage):
|
||||
yield record
|
||||
|
||||
|
||||
def generate_commits(**kwargs):
|
||||
for values in product(**kwargs):
|
||||
def _generate_commits(**kwargs):
|
||||
for values in _product(**kwargs):
|
||||
commit = {
|
||||
'commit_id': str(uuid.uuid4()),
|
||||
'lines_added': 9, 'module': 'nova', 'record_type': 'commit',
|
||||
@@ -99,13 +93,25 @@ def generate_commits(**kwargs):
|
||||
yield commit
|
||||
|
||||
|
||||
def generate_records(record_types, **kwargs):
|
||||
def _generate_records(**kwargs):
|
||||
record_types = kwargs.get('record_type', [])
|
||||
if 'commit' in record_types:
|
||||
for commit in generate_commits(**kwargs):
|
||||
for commit in _generate_commits(**kwargs):
|
||||
yield commit
|
||||
|
||||
|
||||
def product(**kwargs):
|
||||
def make_records(**kwargs):
|
||||
data = {}
|
||||
count = 0
|
||||
for record in _generate_records(**kwargs):
|
||||
record['record_id'] = count
|
||||
data['record:%s' % count] = record
|
||||
count += 1
|
||||
data['record:count'] = count
|
||||
return data
|
||||
|
||||
|
||||
def _product(**kwargs):
|
||||
position_to_key = {}
|
||||
values = []
|
||||
for key, value in kwargs.iteritems():
|
||||
|
@@ -30,8 +30,8 @@ class TestAPIUsers(test_api.TestAPI):
|
||||
{'repos': [{'module': 'nova', 'project_type': 'openstack',
|
||||
'organization': 'openstack',
|
||||
'uri': 'git://github.com/openstack/nova.git'}]},
|
||||
['commit'],
|
||||
user_id=['john_doe', 'bill_smith']):
|
||||
test_api.make_records(record_type=['commit'],
|
||||
user_id=['john_doe', 'bill_smith'])):
|
||||
response = self.app.get('/api/1.0/users')
|
||||
users = json.loads(response.data)['users']
|
||||
self.assertEqual(2, len(users))
|
||||
@@ -43,8 +43,8 @@ class TestAPIUsers(test_api.TestAPI):
|
||||
{'repos': [{'module': 'nova', 'project_type': 'openstack',
|
||||
'organization': 'openstack',
|
||||
'uri': 'git://github.com/openstack/nova.git'}]},
|
||||
['commit'],
|
||||
user_name=['John Doe', 'Bill Smith']):
|
||||
test_api.make_records(record_type=['commit'],
|
||||
user_name=['John Doe', 'Bill Smith'])):
|
||||
response = self.app.get('/api/1.0/users?query=doe')
|
||||
users = json.loads(response.data)['users']
|
||||
self.assertEqual(1, len(users))
|
||||
|
Reference in New Issue
Block a user