Merge "Use base.setup_test_tenant to create test tenant"

This commit is contained in:
Jenkins 2017-04-21 05:48:07 +00:00 committed by Gerrit Code Review
commit 4f97537a51
4 changed files with 23 additions and 83 deletions

View File

@ -42,9 +42,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('162ba316-f18b-4987-8c0c-fd9140cd63ed')
def test_tenant_delete_by_unauthorized_user(self):
# Non-administrator user should not be able to delete a tenant
tenant_name = data_utils.rand_name(name='tenant')
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
self.assertRaises(lib_exc.Forbidden,
self.non_admin_tenants_client.delete_tenant,
tenant['id'])
@ -53,9 +51,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('e450db62-2e9d-418f-893a-54772d6386b1')
def test_tenant_delete_request_without_token(self):
# Request to delete a tenant without a valid token should fail
tenant_name = data_utils.rand_name(name='tenant')
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(lib_exc.Unauthorized,
@ -75,10 +71,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
def test_tenant_create_duplicate(self):
# Tenant names should be unique
tenant_name = data_utils.rand_name(name='tenant')
body = self.tenants_client.create_tenant(name=tenant_name)['tenant']
tenant1_id = body.get('id')
self.addCleanup(self.tenants_client.delete_tenant, tenant1_id)
self.setup_test_tenant(name=tenant_name)
self.assertRaises(lib_exc.Conflict, self.tenants_client.create_tenant,
name=tenant_name)
@ -131,9 +124,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('41704dc5-c5f7-4f79-abfa-76e6fedc570b')
def test_tenant_update_by_unauthorized_user(self):
# Non-administrator user should not be able to update a tenant
tenant_name = data_utils.rand_name(name='tenant')
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
self.assertRaises(lib_exc.Forbidden,
self.non_admin_tenants_client.update_tenant,
tenant['id'])
@ -142,9 +133,7 @@ class TenantsNegativeTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('7a421573-72c7-4c22-a98e-ce539219c657')
def test_tenant_update_request_without_token(self):
# Request to update a tenant without a valid token should fail
tenant_name = data_utils.rand_name(name='tenant')
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
token = self.client.auth_provider.get_token()
self.client.delete_token(token)
self.assertRaises(lib_exc.Unauthorized,

View File

@ -15,7 +15,6 @@
from tempest.api.identity import base
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
@ -26,12 +25,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
# Create several tenants and delete them
tenants = []
for _ in range(3):
tenant_name = data_utils.rand_name(name='tenant-new')
tenant = self.tenants_client.create_tenant(
name=tenant_name)['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
tenants.append(tenant)
tenant_ids = [tn['id'] for tn in tenants]
body = self.tenants_client.list_tenants()['tenants']
@ -48,14 +42,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('d25e9f24-1310-4d29-b61b-d91299c21d6d')
def test_tenant_create_with_description(self):
# Create tenant with a description
tenant_name = data_utils.rand_name(name='tenant')
tenant_desc = data_utils.rand_name(name='desc')
body = self.tenants_client.create_tenant(name=tenant_name,
description=tenant_desc)
tenant = body['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant(description=tenant_desc)
tenant_id = tenant['id']
desc1 = tenant['description']
self.assertEqual(desc1, tenant_desc, 'Description should have '
@ -69,13 +57,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('670bdddc-1cd7-41c7-b8e2-751cfb67df50')
def test_tenant_create_enabled(self):
# Create a tenant that is enabled
tenant_name = data_utils.rand_name(name='tenant')
body = self.tenants_client.create_tenant(name=tenant_name,
enabled=True)
tenant = body['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant(enabled=True)
tenant_id = tenant['id']
en1 = tenant['enabled']
self.assertTrue(en1, 'Enable should be True in response')
@ -87,13 +69,7 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('3be22093-b30f-499d-b772-38340e5e16fb')
def test_tenant_create_not_enabled(self):
# Create a tenant that is not enabled
tenant_name = data_utils.rand_name(name='tenant')
body = self.tenants_client.create_tenant(name=tenant_name,
enabled=False)
tenant = body['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant(enabled=False)
tenant_id = tenant['id']
en1 = tenant['enabled']
self.assertEqual('false', str(en1).lower(),
@ -108,14 +84,9 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
def test_tenant_update_name(self):
# Update name attribute of a tenant
t_name1 = data_utils.rand_name(name='tenant')
body = self.tenants_client.create_tenant(name=t_name1)['tenant']
tenant = body
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
t_id = body['id']
resp1_name = body['name']
tenant = self.setup_test_tenant(name=t_name1)
t_id = tenant['id']
resp1_name = tenant['name']
t_name2 = data_utils.rand_name(name='tenant2')
body = self.tenants_client.update_tenant(t_id, name=t_name2)['tenant']
@ -134,15 +105,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('859fcfe1-3a03-41ef-86f9-b19a47d1cd87')
def test_tenant_update_desc(self):
# Update description attribute of a tenant
t_name = data_utils.rand_name(name='tenant')
t_desc = data_utils.rand_name(name='desc')
body = self.tenants_client.create_tenant(name=t_name,
description=t_desc)
tenant = body['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant(description=t_desc)
t_id = tenant['id']
resp1_desc = tenant['description']
@ -164,14 +128,8 @@ class TenantsTestJSON(base.BaseIdentityV2AdminTest):
@decorators.idempotent_id('8fc8981f-f12d-4c66-9972-2bdcf2bc2e1a')
def test_tenant_update_enable(self):
# Update the enabled attribute of a tenant
t_name = data_utils.rand_name(name='tenant')
t_en = False
body = self.tenants_client.create_tenant(name=t_name, enabled=t_en)
tenant = body['tenant']
# Add the tenant to the cleanup list
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant(enabled=t_en)
t_id = tenant['id']
resp1_en = tenant['enabled']

View File

@ -26,10 +26,7 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
user_name = data_utils.rand_name(name='user')
user_password = data_utils.rand_password()
# first:create a tenant
tenant_name = data_utils.rand_name(name='tenant')
tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
# Delete the tenant at the end of the test
self.addCleanup(self.tenants_client.delete_tenant, tenant['id'])
tenant = self.setup_test_tenant()
# second:create a user
user = self.create_test_user(name=user_name,
password=user_password,
@ -70,16 +67,10 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
# Create a couple tenants.
tenant1_name = data_utils.rand_name(name='tenant')
tenant1 = self.tenants_client.create_tenant(
name=tenant1_name)['tenant']
# Delete the tenant at the end of the test
self.addCleanup(self.tenants_client.delete_tenant, tenant1['id'])
tenant1 = self.setup_test_tenant(name=tenant1_name)
tenant2_name = data_utils.rand_name(name='tenant')
tenant2 = self.tenants_client.create_tenant(
name=tenant2_name)['tenant']
# Delete the tenant at the end of the test
self.addCleanup(self.tenants_client.delete_tenant, tenant2['id'])
tenant2 = self.setup_test_tenant(name=tenant2_name)
# Create a role
role = self.setup_test_role()

View File

@ -152,11 +152,13 @@ class BaseIdentityV2AdminTest(BaseIdentityV2Test):
user = self.create_test_user(tenantId=tenant['id'], password=password)
return user
def setup_test_tenant(self):
def setup_test_tenant(self, **kwargs):
"""Set up a test tenant."""
tenant = self.projects_client.create_tenant(
name=data_utils.rand_name('test_tenant'),
description=data_utils.rand_name('desc'))['tenant']
if 'name' not in kwargs:
kwargs['name'] = data_utils.rand_name('test_tenant')
if 'description' not in kwargs:
kwargs['description'] = data_utils.rand_name('desc')
tenant = self.projects_client.create_tenant(**kwargs)['tenant']
# Delete the tenant at the end of the test
self.addCleanup(
test_utils.call_and_ignore_notfound_exc,