Merge "Add specific values to specific fields in get_random_object_fields()"

This commit is contained in:
Jenkins 2017-07-27 17:04:25 +00:00 committed by Gerrit Code Review
commit 05e91d3888
2 changed files with 6 additions and 1 deletions

View File

@ -519,6 +519,7 @@ class _BaseObjectTestCase(object):
objects.register_objects()
self.context = context.get_admin_context()
self._unique_tracker = collections.defaultdict(set)
self.locked_obj_fields = collections.defaultdict(set)
self.db_objs = [
self._test_class.db_model(**self.get_random_db_fields())
for _ in range(3)
@ -562,6 +563,9 @@ class _BaseObjectTestCase(object):
if field not in obj_cls.synthetic_fields:
generator = FIELD_TYPE_VALUE_GENERATOR_MAP[type(field_obj)]
fields[field] = get_value(generator, ip_version)
for k, v in self.locked_obj_fields.items():
if k in fields:
fields[k] = v
for keys in obj_cls.unique_keys:
keytup = tuple(keys)
unique_values = tuple(fields[k] for k in keytup)
@ -611,6 +615,7 @@ class _BaseObjectTestCase(object):
obj[k] = val
if k in self.valid_field_filter:
self.valid_field_filter[k] = val
self.locked_obj_fields[k] = v() if callable(v) else v
@classmethod
def generate_object_keys(cls, obj_cls, field_names=None):

View File

@ -31,7 +31,7 @@ class RouterL3AgentBindingDbObjTestCase(test_base.BaseDbObjectTestCase,
super(RouterL3AgentBindingDbObjTestCase, self).setUp()
router_id = self._create_test_router_id()
index = iter(range(1, len(self.objs) + 1))
index = iter(range(1, len(self.objs) + 2))
self.update_obj_fields(
{'router_id': router_id,
'binding_index': lambda: next(index),