]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Code refactor for generating integer in testcase
authorManjeet Singh Bhatia <manjeet.s.bhatia@intel.com>
Fri, 2 Oct 2015 21:36:22 +0000 (17:36 -0400)
committerArmando Migliaccio <armamig@gmail.com>
Thu, 8 Oct 2015 17:57:37 +0000 (17:57 +0000)
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

neutron/tests/tools.py
neutron/tests/unit/objects/test_base.py

index 0130ec23fc5d8af4d39b7ba2eb745175eeb8d0fc..7d01cbe1481d788f086c52a74f7cc06e4c748907 100644 (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)
index 1682a7d011514e96f5843b78268e7b31a8a8c3e4..00afb8a62ee8ba186ba00f85bcd3ef1ee9c36e1b 100644 (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: []