From ee8bc191598d27422925c5bdd09ac4fc2d56f27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Nov=C3=A1=C4=8Dik?= Date: Sat, 27 Dec 2014 11:15:26 +0100 Subject: [PATCH] Add general function for generating random names Adding function gen_random_resource_name for generation random resources that should be used in the integration tests. Mentioned method automatically adds horizon string into the resource name in order to clearly distinguish resource origin. Also timestamp is added for better debugging of the tests in more complex testcases. uuid4 function is used to minimize resource name collisions. Closes-Bug: #1399219 Partially implements blueprint: selenium-integration-testing Change-Id: Id5cb26e50b7b442af69798a2928be514adf7d8fe --- .../test/integration_tests/helpers.py | 21 +++++++++++++++++++ .../integration_tests/tests/test_flavors.py | 4 +--- .../tests/test_image_create_delete.py | 4 +--- .../integration_tests/tests/test_keypair.py | 4 +--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py index 5c9958a0d5..5710ff70bf 100644 --- a/openstack_dashboard/test/integration_tests/helpers.py +++ b/openstack_dashboard/test/integration_tests/helpers.py @@ -11,6 +11,8 @@ # under the License. import os +import time +import uuid from selenium.webdriver.support import ui import testtools @@ -21,6 +23,25 @@ from openstack_dashboard.test.integration_tests.pages import loginpage from openstack_dashboard.test.integration_tests import webdriver +def gen_random_resource_name(resource="", timestamp=True): + """Generate random resource name using uuid and timestamp. + + Input fields are usually limited to 255 or 80 characters hence their + provide enough space for quite long resource names, but it might be + the case that maximum field length is quite restricted, it is then + necessary to consider using shorter resource argument or avoid using + timestamp by setting timestamp argument to False. + """ + fields = ["horizon"] + if resource: + fields.append(resource) + if timestamp: + tstamp = time.strftime("%d-%m-%H-%M-%S") + fields.append(tstamp) + fields.append(str(uuid.uuid4()).replace("-", "")) + return "_".join(fields) + + class BaseTestCase(testtools.TestCase): def setUp(self): diff --git a/openstack_dashboard/test/integration_tests/tests/test_flavors.py b/openstack_dashboard/test/integration_tests/tests/test_flavors.py index 07525faed9..810cb38dd7 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_flavors.py +++ b/openstack_dashboard/test/integration_tests/tests/test_flavors.py @@ -10,13 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestFlavors(helpers.AdminTestCase): - FLAVOR_NAME = 'horizonflavor_' + str(uuid.uuid4()) + FLAVOR_NAME = helpers.gen_random_resource_name("flavor") def test_flavor_create(self): """tests the flavor creation and deletion functionalities: diff --git a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py index e22fb888d6..7c82af6899 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py +++ b/openstack_dashboard/test/integration_tests/tests/test_image_create_delete.py @@ -10,13 +10,11 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestImage(helpers.TestCase): - IMAGE_NAME = 'horizonimage_' + str(uuid.uuid4()) + IMAGE_NAME = helpers.gen_random_resource_name("image") def test_image_create_delete(self): """tests the image creation and deletion functionalities: diff --git a/openstack_dashboard/test/integration_tests/tests/test_keypair.py b/openstack_dashboard/test/integration_tests/tests/test_keypair.py index 613d8d075e..45783b19e9 100644 --- a/openstack_dashboard/test/integration_tests/tests/test_keypair.py +++ b/openstack_dashboard/test/integration_tests/tests/test_keypair.py @@ -13,14 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -import uuid - from openstack_dashboard.test.integration_tests import helpers class TestKeypair(helpers.TestCase): """Checks that the user is able to create/delete keypair.""" - KEYPAIR_NAME = 'horizonkeypair_' + str(uuid.uuid4()) + KEYPAIR_NAME = helpers.gen_random_resource_name("keypair") def test_keypair(self): keypair_page = self.home_pg.go_to_accessandsecurity_keypairspage()