From: Angus Salkeld Date: Wed, 31 Jul 2013 05:42:21 +0000 (+1000) Subject: Move the random_name() function from loadbalancer to utils X-Git-Tag: 2014.1~300 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f42b3873ae0d9cb45de9c20875d693be528cb4c5;p=openstack-build%2Fheat-build.git Move the random_name() function from loadbalancer to utils (handy to make a random stack_name) Change-Id: I79055e2eba7aa2dd9ebcc09fbe4de87fe4483df5 --- diff --git a/heat/tests/test_cloud_loadbalancer.py b/heat/tests/test_cloud_loadbalancer.py index 583221d3..dbe2cdff 100644 --- a/heat/tests/test_cloud_loadbalancer.py +++ b/heat/tests/test_cloud_loadbalancer.py @@ -16,16 +16,13 @@ import uuid import json import copy -import random -import string from heat.common import template_format from heat.engine import scheduler from heat.engine import resource from heat.engine.resources.rackspace import cloud_loadbalancer as lb from heat.tests.common import HeatTestCase -from heat.tests.utils import setup_dummy_db -from heat.tests.utils import parse_stack +from heat.tests import utils # The following fakes are for pyrax @@ -200,7 +197,7 @@ class LoadBalancerTest(HeatTestCase): } lb.resource_mapping = override_resource - setup_dummy_db() + utils.setup_dummy_db() resource._register_class("Rackspace::Cloud::LoadBalancer", LoadBalancerWithFakeClient) @@ -225,13 +222,9 @@ class LoadBalancerTest(HeatTestCase): def _get_first_resource_name(self, templ): return next(k for k in templ['Resources']) - def _random_name(self): - return ''.join(random.choice(string.ascii_uppercase) - for x in range(10)) - def _mock_loadbalancer(self, lb_template, expected_name, expected_body): t = template_format.parse(json.dumps(lb_template)) - s = parse_stack(t, stack_name=self._random_name()) + s = utils.parse_stack(t, stack_name=utils.random_name()) rsrc, fake_loadbalancer = self._mock_create(t, s, self. diff --git a/heat/tests/utils.py b/heat/tests/utils.py index 220ade0c..0550addd 100644 --- a/heat/tests/utils.py +++ b/heat/tests/utils.py @@ -12,8 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. -import sys import functools +import random +import string +import sys from heat.common import context from heat.common import exception @@ -24,6 +26,11 @@ from heat.db.sqlalchemy.session import get_engine from heat.db import migration +def random_name(): + return ''.join(random.choice(string.ascii_uppercase) + for x in range(10)) + + def stack_delete_after(test_fn): """ Decorator which calls test class self.stack.delete()