summaryrefslogtreecommitdiff
path: root/functional/tests/identity/v2
diff options
context:
space:
mode:
authorCedric Brandily <zzelle@gmail.com>2016-04-06 00:54:31 +0200
committerCedric Brandily <zzelle@gmail.com>2016-04-06 20:43:21 +0200
commite2e9c49cd920947eec1f873e74a98ec5ab6834fd (patch)
tree9cd34cb1360637ae2db6bacd282afe1fca930347 /functional/tests/identity/v2
parentc3f6ee95709d1ccb7de7818e4403645a1e9a5662 (diff)
downloadpython-openstackclient-e2e9c49cd920947eec1f873e74a98ec5ab6834fd.tar.gz
Correct addCleanup use in functests
This change replaces in many identity functests the pattern: raw_resource = create_resource(...) check(raw_resource) self.addCleanup(delete_resource, ...) ... by the pattern: raw_resource = create_resource(...) self.addCleanup(delete_resource, ...) check(raw_resource) ... which ensures that cleanup is defined and called after the test even if check(resource) fails. Change-Id: I4da541b7552d06eaffafda446e389bb552422cda
Diffstat (limited to 'functional/tests/identity/v2')
-rw-r--r--functional/tests/identity/v2/test_identity.py30
-rw-r--r--functional/tests/identity/v2/test_role.py31
2 files changed, 31 insertions, 30 deletions
diff --git a/functional/tests/identity/v2/test_identity.py b/functional/tests/identity/v2/test_identity.py
index 91a77b67..4346499c 100644
--- a/functional/tests/identity/v2/test_identity.py
+++ b/functional/tests/identity/v2/test_identity.py
@@ -67,13 +67,13 @@ class IdentityTests(test.TestCase):
'--description %(description)s '
'--enable %(name)s' % {'description': project_description,
'name': project_name})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.PROJECT_FIELDS)
project = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(
self.openstack,
'project delete %s' % project['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.PROJECT_FIELDS)
return project_name
def _create_dummy_user(self, add_clean_up=True):
@@ -90,47 +90,47 @@ class IdentityTests(test.TestCase):
'email': email,
'password': password,
'name': username})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.USER_FIELDS)
if add_clean_up:
self.addCleanup(
self.openstack,
'user delete %s' % self.parse_show_as_object(raw_output)['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.USER_FIELDS)
return username
def _create_dummy_role(self, add_clean_up=True):
role_name = data_utils.rand_name('TestRole')
raw_output = self.openstack('role create %s' % role_name)
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.ROLE_FIELDS)
role = self.parse_show_as_object(raw_output)
- self.assertEqual(role_name, role['name'])
if add_clean_up:
self.addCleanup(
self.openstack,
'role delete %s' % role['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.ROLE_FIELDS)
+ self.assertEqual(role_name, role['name'])
return role_name
def _create_dummy_ec2_credentials(self, add_clean_up=True):
raw_output = self.openstack('ec2 credentials create')
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS)
ec2_credentials = self.parse_show_as_object(raw_output)
access_key = ec2_credentials['access']
if add_clean_up:
self.addCleanup(
self.openstack,
'ec2 credentials delete %s' % access_key)
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.EC2_CREDENTIALS_FIELDS)
return access_key
def _create_dummy_token(self, add_clean_up=True):
raw_output = self.openstack('token issue')
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.TOKEN_FIELDS)
token = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(self.openstack,
'token revoke %s' % token['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.TOKEN_FIELDS)
return token['id']
def _create_dummy_service(self, add_clean_up=True):
@@ -144,12 +144,12 @@ class IdentityTests(test.TestCase):
'%(type)s' % {'name': service_name,
'description': description,
'type': type_name})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.SERVICE_FIELDS)
if add_clean_up:
service = self.parse_show_as_object(raw_output)
self.addCleanup(self.openstack,
'service delete %s' % service['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.SERVICE_FIELDS)
return service_name
def _create_dummy_endpoint(self, add_clean_up=True):
@@ -169,11 +169,11 @@ class IdentityTests(test.TestCase):
'internalurl': internal_url,
'region': region_id,
'service': service_name})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.ENDPOINT_FIELDS)
endpoint = self.parse_show_as_object(raw_output)
if add_clean_up:
self.addCleanup(
self.openstack,
'endpoint delete %s' % endpoint['id'])
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.ENDPOINT_FIELDS)
return endpoint['id']
diff --git a/functional/tests/identity/v2/test_role.py b/functional/tests/identity/v2/test_role.py
index e542a5fb..9ee60069 100644
--- a/functional/tests/identity/v2/test_role.py
+++ b/functional/tests/identity/v2/test_role.py
@@ -40,8 +40,17 @@ class RoleTests(test_identity.IdentityTests):
'%(role)s' % {'project': project_name,
'user': username,
'role': role_name})
+ self.addCleanup(
+ self.openstack,
+ 'role remove '
+ '--project %(project)s '
+ '--user %(user)s '
+ '%(role)s' % {'project': project_name,
+ 'user': username,
+ 'role': role_name})
items = self.parse_show(raw_output)
self.assert_show_fields(items, self.ROLE_FIELDS)
+
raw_output = self.openstack(
'role list '
'--project %(project)s '
@@ -51,14 +60,6 @@ class RoleTests(test_identity.IdentityTests):
items = self.parse_listing(raw_output)
self.assert_table_structure(items, test_identity.BASIC_LIST_HEADERS)
self.assertEqual(1, len(items))
- self.addCleanup(
- self.openstack,
- 'role remove '
- '--project %(project)s '
- '--user %(user)s '
- '%(role)s' % {'project': project_name,
- 'user': username,
- 'role': role_name})
def test_role_show(self):
role_name = self._create_dummy_role()
@@ -76,8 +77,6 @@ class RoleTests(test_identity.IdentityTests):
'%(role)s' % {'project': self.project_name,
'user': username,
'role': role_name})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.ROLE_FIELDS)
self.addCleanup(
self.openstack,
'role remove '
@@ -86,24 +85,26 @@ class RoleTests(test_identity.IdentityTests):
'%(role)s' % {'project': self.project_name,
'user': username,
'role': role_name})
+ items = self.parse_show(raw_output)
+ self.assert_show_fields(items, self.ROLE_FIELDS)
def test_role_remove(self):
role_name = self._create_dummy_role()
username = self._create_dummy_user()
- raw_output = self.openstack(
+ add_raw_output = self.openstack(
'role add '
'--project %(project)s '
'--user %(user)s '
'%(role)s' % {'project': self.project_name,
'user': username,
'role': role_name})
- items = self.parse_show(raw_output)
- self.assert_show_fields(items, self.ROLE_FIELDS)
- raw_output = self.openstack(
+ del_raw_output = self.openstack(
'role remove '
'--project %(project)s '
'--user %(user)s '
'%(role)s' % {'project': self.project_name,
'user': username,
'role': role_name})
- self.assertEqual(0, len(raw_output))
+ items = self.parse_show(add_raw_output)
+ self.assert_show_fields(items, self.ROLE_FIELDS)
+ self.assertEqual(0, len(del_raw_output))