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
This commit is contained in:
Tomáš Nováčik 2014-12-27 11:15:26 +01:00
parent aeb3325cfb
commit ee8bc19159
4 changed files with 24 additions and 9 deletions

View File

@ -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):

View File

@ -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:

View File

@ -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:

View File

@ -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()