Code refactor for generating integer in testcase

This will remove the need of import random in unit/objects/test_base.py
as its already done in tests/tools.py and some of the functions are
called from there.

Change-Id: Icf1d5518f9f394b534e3b75cfe55f2adf7fe5169
This commit is contained in:
Manjeet Singh Bhatia 2015-10-02 17:36:22 -04:00 committed by Armando Migliaccio
parent a15651cca1
commit 4a73c85a9f
2 changed files with 5 additions and 6 deletions

View File

@ -131,3 +131,7 @@ def get_random_string(n=10):
def get_random_boolean():
return bool(random.getrandbits(1))
def get_random_integer(range_begin=0, range_end=1000):
return random.randint(range_begin, range_end)

View File

@ -11,7 +11,6 @@
# under the License.
import copy
import random
import mock
from oslo_db import exception as obj_exc
@ -53,13 +52,9 @@ class FakeNeutronObject(base.NeutronDbObject):
synthetic_fields = ['field2']
def _random_integer():
return random.randint(0, 1000)
FIELD_TYPE_VALUE_GENERATOR_MAP = {
obj_fields.BooleanField: tools.get_random_boolean,
obj_fields.IntegerField: _random_integer,
obj_fields.IntegerField: tools.get_random_integer,
obj_fields.StringField: tools.get_random_string,
obj_fields.UUIDField: tools.get_random_string,
obj_fields.ListOfObjectsField: lambda: []