add some negative tests for tenant
making a separate test_tenant_negative.py,and move the exist negative
tests over to it,and add some negative tests for in it.
- test_update_non_existent_tenant
- test_tenant_update_by_unauthorized_user
- test_tenant_update_request_without_token
Change-Id: Id0d15d312c96a3f8a244d5e08414623e3c15013a
diff --git a/tempest/api/identity/admin/test_tenant_negative.py b/tempest/api/identity/admin/test_tenant_negative.py
new file mode 100644
index 0000000..6875bf5
--- /dev/null
+++ b/tempest/api/identity/admin/test_tenant_negative.py
@@ -0,0 +1,148 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2013 Huawei Technologies Co.,LTD.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import uuid
+
+from tempest.api.identity import base
+from tempest.common.utils import data_utils
+from tempest import exceptions
+from tempest.test import attr
+
+
+class TenantsNegativeTestJSON(base.BaseIdentityAdminTest):
+ _interface = 'json'
+
+ @attr(type=['negative', 'gate'])
+ def test_list_tenants_by_unauthorized_user(self):
+ # Non-administrator user should not be able to list tenants
+ self.assertRaises(exceptions.Unauthorized,
+ self.non_admin_client.list_tenants)
+
+ @attr(type=['negative', 'gate'])
+ def test_list_tenant_request_without_token(self):
+ # Request to list tenants without a valid token should fail
+ token = self.client.get_auth()
+ self.client.delete_token(token)
+ self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
+ self.client.clear_auth()
+
+ @attr(type=['negative', 'gate'])
+ 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-')
+ resp, tenant = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
+ self.data.tenants.append(tenant)
+ self.assertRaises(exceptions.Unauthorized,
+ self.non_admin_client.delete_tenant, tenant['id'])
+
+ @attr(type=['negative', 'gate'])
+ 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-')
+ resp, tenant = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
+ self.data.tenants.append(tenant)
+ token = self.client.get_auth()
+ self.client.delete_token(token)
+ self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
+ tenant['id'])
+ self.client.clear_auth()
+
+ @attr(type=['negative', 'gate'])
+ def test_delete_non_existent_tenant(self):
+ # Attempt to delete a non existent tenant should fail
+ self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
+ str(uuid.uuid4().hex))
+
+ @attr(type=['negative', 'gate'])
+ def test_tenant_create_duplicate(self):
+ # Tenant names should be unique
+ tenant_name = data_utils.rand_name(name='tenant-')
+ resp, body = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
+ tenant = body
+ self.data.tenants.append(tenant)
+ tenant1_id = body.get('id')
+
+ self.addCleanup(self.client.delete_tenant, tenant1_id)
+ self.addCleanup(self.data.tenants.remove, tenant)
+ self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
+ tenant_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_tenant_by_unauthorized_user(self):
+ # Non-administrator user should not be authorized to create a tenant
+ tenant_name = data_utils.rand_name(name='tenant-')
+ self.assertRaises(exceptions.Unauthorized,
+ self.non_admin_client.create_tenant, tenant_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_create_tenant_request_without_token(self):
+ # Create tenant request without a token should not be authorized
+ tenant_name = data_utils.rand_name(name='tenant-')
+ token = self.client.get_auth()
+ self.client.delete_token(token)
+ self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
+ tenant_name)
+ self.client.clear_auth()
+
+ @attr(type=['negative', 'gate'])
+ def test_create_tenant_with_empty_name(self):
+ # Tenant name should not be empty
+ self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
+ name='')
+
+ @attr(type=['negative', 'gate'])
+ def test_create_tenants_name_length_over_64(self):
+ # Tenant name length should not be greater than 64 characters
+ tenant_name = 'a' * 65
+ self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
+ tenant_name)
+
+ @attr(type=['negative', 'gate'])
+ def test_update_non_existent_tenant(self):
+ # Attempt to update a non existent tenant should fail
+ self.assertRaises(exceptions.NotFound, self.client.update_tenant,
+ str(uuid.uuid4().hex))
+
+ @attr(type=['negative', 'gate'])
+ 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-')
+ resp, tenant = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
+ self.data.tenants.append(tenant)
+ self.assertRaises(exceptions.Unauthorized,
+ self.non_admin_client.update_tenant, tenant['id'])
+
+ @attr(type=['negative', 'gate'])
+ 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-')
+ resp, tenant = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
+ self.data.tenants.append(tenant)
+ token = self.client.get_auth()
+ self.client.delete_token(token)
+ self.assertRaises(exceptions.Unauthorized, self.client.update_tenant,
+ tenant['id'])
+ self.client.clear_auth()
+
+
+class TenantsNegativeTestXML(TenantsNegativeTestJSON):
+ _interface = 'xml'
diff --git a/tempest/api/identity/admin/test_tenants.py b/tempest/api/identity/admin/test_tenants.py
index 486b739..e36b543 100644
--- a/tempest/api/identity/admin/test_tenants.py
+++ b/tempest/api/identity/admin/test_tenants.py
@@ -16,8 +16,7 @@
# under the License.
from tempest.api.identity import base
-from tempest.common.utils.data_utils import rand_name
-from tempest import exceptions
+from tempest.common.utils import data_utils
from tempest.test import attr
@@ -25,25 +24,13 @@
_interface = 'json'
@attr(type='gate')
- def test_list_tenants_by_unauthorized_user(self):
- # Non-administrator user should not be able to list tenants
- self.assertRaises(exceptions.Unauthorized,
- self.non_admin_client.list_tenants)
-
- @attr(type='gate')
- def test_list_tenant_request_without_token(self):
- # Request to list tenants without a valid token should fail
- token = self.client.get_auth()
- self.client.delete_token(token)
- self.assertRaises(exceptions.Unauthorized, self.client.list_tenants)
- self.client.clear_auth()
-
- @attr(type='gate')
def test_tenant_list_delete(self):
# Create several tenants and delete them
tenants = []
for _ in xrange(3):
- resp, tenant = self.client.create_tenant(rand_name('tenant-new'))
+ tenant_name = data_utils.rand_name(name='tenant-new')
+ resp, tenant = self.client.create_tenant(tenant_name)
+ self.assertEqual(200, resp.status)
self.data.tenants.append(tenant)
tenants.append(tenant)
tenant_ids = map(lambda x: x['id'], tenants)
@@ -62,37 +49,10 @@
self.assertFalse(any(found), 'Tenants failed to delete')
@attr(type='gate')
- def test_tenant_delete_by_unauthorized_user(self):
- # Non-administrator user should not be able to delete a tenant
- tenant_name = rand_name('tenant-')
- resp, tenant = self.client.create_tenant(tenant_name)
- self.data.tenants.append(tenant)
- self.assertRaises(exceptions.Unauthorized,
- self.non_admin_client.delete_tenant, tenant['id'])
-
- @attr(type='gate')
- def test_tenant_delete_request_without_token(self):
- # Request to delete a tenant without a valid token should fail
- tenant_name = rand_name('tenant-')
- resp, tenant = self.client.create_tenant(tenant_name)
- self.data.tenants.append(tenant)
- token = self.client.get_auth()
- self.client.delete_token(token)
- self.assertRaises(exceptions.Unauthorized, self.client.delete_tenant,
- tenant['id'])
- self.client.clear_auth()
-
- @attr(type='gate')
- def test_delete_non_existent_tenant(self):
- # Attempt to delete a non existent tenant should fail
- self.assertRaises(exceptions.NotFound, self.client.delete_tenant,
- 'junk_tenant_123456abc')
-
- @attr(type='gate')
def test_tenant_create_with_description(self):
# Create tenant with a description
- tenant_name = rand_name('tenant-')
- tenant_desc = rand_name('desc-')
+ tenant_name = data_utils.rand_name(name='tenant-')
+ tenant_desc = data_utils.rand_name(name='desc-')
resp, body = self.client.create_tenant(tenant_name,
description=tenant_desc)
tenant = body
@@ -113,7 +73,7 @@
@attr(type='gate')
def test_tenant_create_enabled(self):
# Create a tenant that is enabled
- tenant_name = rand_name('tenant-')
+ tenant_name = data_utils.rand_name(name='tenant-')
resp, body = self.client.create_tenant(tenant_name, enabled=True)
tenant = body
self.data.tenants.append(tenant)
@@ -131,7 +91,7 @@
@attr(type='gate')
def test_tenant_create_not_enabled(self):
# Create a tenant that is not enabled
- tenant_name = rand_name('tenant-')
+ tenant_name = data_utils.rand_name(name='tenant-')
resp, body = self.client.create_tenant(tenant_name, enabled=False)
tenant = body
self.data.tenants.append(tenant)
@@ -149,61 +109,18 @@
self.data.tenants.remove(tenant)
@attr(type='gate')
- def test_tenant_create_duplicate(self):
- # Tenant names should be unique
- tenant_name = rand_name('tenant-dup-')
- resp, body = self.client.create_tenant(tenant_name)
- tenant = body
- self.data.tenants.append(tenant)
- tenant1_id = body.get('id')
-
- self.addCleanup(self.client.delete_tenant, tenant1_id)
- self.addCleanup(self.data.tenants.remove, tenant)
- self.assertRaises(exceptions.Duplicate, self.client.create_tenant,
- tenant_name)
-
- @attr(type='gate')
- def test_create_tenant_by_unauthorized_user(self):
- # Non-administrator user should not be authorized to create a tenant
- tenant_name = rand_name('tenant-')
- self.assertRaises(exceptions.Unauthorized,
- self.non_admin_client.create_tenant, tenant_name)
-
- @attr(type='gate')
- def test_create_tenant_request_without_token(self):
- # Create tenant request without a token should not be authorized
- tenant_name = rand_name('tenant-')
- token = self.client.get_auth()
- self.client.delete_token(token)
- self.assertRaises(exceptions.Unauthorized, self.client.create_tenant,
- tenant_name)
- self.client.clear_auth()
-
- @attr(type='gate')
- def test_create_tenant_with_empty_name(self):
- # Tenant name should not be empty
- self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
- name='')
-
- @attr(type='gate')
- def test_create_tenants_name_length_over_64(self):
- # Tenant name length should not be greater than 64 characters
- tenant_name = 'a' * 65
- self.assertRaises(exceptions.BadRequest, self.client.create_tenant,
- tenant_name)
-
- @attr(type='gate')
def test_tenant_update_name(self):
# Update name attribute of a tenant
- t_name1 = rand_name('tenant-')
+ t_name1 = data_utils.rand_name(name='tenant-')
resp, body = self.client.create_tenant(t_name1)
+ self.assertEqual(200, resp.status)
tenant = body
self.data.tenants.append(tenant)
t_id = body['id']
resp1_name = body['name']
- t_name2 = rand_name('tenant2-')
+ t_name2 = data_utils.rand_name(name='tenant2-')
resp, body = self.client.update_tenant(t_id, name=t_name2)
st2 = resp['status']
resp2_name = body['name']
@@ -223,16 +140,17 @@
@attr(type='gate')
def test_tenant_update_desc(self):
# Update description attribute of a tenant
- t_name = rand_name('tenant-')
- t_desc = rand_name('desc-')
+ t_name = data_utils.rand_name(name='tenant-')
+ t_desc = data_utils.rand_name(name='desc-')
resp, body = self.client.create_tenant(t_name, description=t_desc)
+ self.assertEqual(200, resp.status)
tenant = body
self.data.tenants.append(tenant)
t_id = body['id']
resp1_desc = body['description']
- t_desc2 = rand_name('desc2-')
+ t_desc2 = data_utils.rand_name(name='desc2-')
resp, body = self.client.update_tenant(t_id, description=t_desc2)
st2 = resp['status']
resp2_desc = body['description']
@@ -252,9 +170,10 @@
@attr(type='gate')
def test_tenant_update_enable(self):
# Update the enabled attribute of a tenant
- t_name = rand_name('tenant-')
+ t_name = data_utils.rand_name(name='tenant-')
t_en = False
resp, body = self.client.create_tenant(t_name, enabled=t_en)
+ self.assertEqual(200, resp.status)
tenant = body
self.data.tenants.append(tenant)