blob: 7cae856a22bea9b078617be5f91b24cd234c1fcc [file] [log] [blame]
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Sean Dague1937d092013-05-17 16:36:38 -040016from tempest.api.identity import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053018from tempest.test import attr
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053019
20
21class UsersV3TestJSON(base.BaseIdentityAdminTest):
22 _interface = 'json'
23
Giampaolo Lauriaea294952013-05-15 08:52:04 -040024 @attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053025 def test_user_update(self):
26 # Test case to check if updating of user attributes is successful.
Attila Fazekasf7f34f92013-08-01 17:01:44 +020027 # Creating first user
Masayuki Igawa259c1132013-10-31 17:48:44 +090028 u_name = data_utils.rand_name('user-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053029 u_desc = u_name + 'description'
30 u_email = u_name + '@testmail.tm'
Masayuki Igawa259c1132013-10-31 17:48:44 +090031 u_password = data_utils.rand_name('pass-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053032 resp, user = self.v3_client.create_user(
33 u_name, description=u_desc, password=u_password,
34 email=u_email, enabled=False)
35 # Delete the User at the end of this method
36 self.addCleanup(self.v3_client.delete_user, user['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020037 # Creating second project for updation
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053038 resp, project = self.v3_client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +090039 data_utils.rand_name('project-'),
40 description=data_utils.rand_name('project-desc-'))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053041 # Delete the Project at the end of this method
42 self.addCleanup(self.v3_client.delete_project, project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020043 # Updating user details with new values
Masayuki Igawa259c1132013-10-31 17:48:44 +090044 u_name2 = data_utils.rand_name('user2-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053045 u_email2 = u_name2 + '@testmail.tm'
46 u_description2 = u_name2 + ' description'
47 resp, update_user = self.v3_client.update_user(
48 user['id'], name=u_name2, description=u_description2,
49 project_id=project['id'],
50 email=u_email2, enabled=False)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020051 # Assert response body of update user.
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053052 self.assertEqual(200, resp.status)
53 self.assertEqual(u_name2, update_user['name'])
54 self.assertEqual(u_description2, update_user['description'])
55 self.assertEqual(project['id'],
56 update_user['project_id'])
57 self.assertEqual(u_email2, update_user['email'])
58 self.assertEqual('false', str(update_user['enabled']).lower())
Attila Fazekasf7f34f92013-08-01 17:01:44 +020059 # GET by id after updation
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053060 resp, new_user_get = self.v3_client.get_user(user['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020061 # Assert response body of GET after updation
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053062 self.assertEqual(u_name2, new_user_get['name'])
63 self.assertEqual(u_description2, new_user_get['description'])
64 self.assertEqual(project['id'],
65 new_user_get['project_id'])
66 self.assertEqual(u_email2, new_user_get['email'])
67 self.assertEqual('false', str(new_user_get['enabled']).lower())
68
Giampaolo Lauriaea294952013-05-15 08:52:04 -040069 @attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053070 def test_list_user_projects(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020071 # List the projects that a user has access upon
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053072 assigned_project_ids = list()
73 fetched_project_ids = list()
74 _, u_project = self.v3_client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +090075 data_utils.rand_name('project-'),
76 description=data_utils.rand_name('project-desc-'))
Mitsuhiko Yamazakif58442e2013-05-13 15:46:44 +090077 # Delete the Project at the end of this method
78 self.addCleanup(self.v3_client.delete_project, u_project['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020079 # Create a user.
Masayuki Igawa259c1132013-10-31 17:48:44 +090080 u_name = data_utils.rand_name('user-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053081 u_desc = u_name + 'description'
82 u_email = u_name + '@testmail.tm'
Masayuki Igawa259c1132013-10-31 17:48:44 +090083 u_password = data_utils.rand_name('pass-')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053084 _, user_body = self.v3_client.create_user(
85 u_name, description=u_desc, password=u_password,
86 email=u_email, enabled=False, project_id=u_project['id'])
87 # Delete the User at the end of this method
88 self.addCleanup(self.v3_client.delete_user, user_body['id'])
89 # Creating Role
Masayuki Igawa259c1132013-10-31 17:48:44 +090090 _, role_body = self.v3_client.create_role(
91 data_utils.rand_name('role-'))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053092 # Delete the Role at the end of this method
93 self.addCleanup(self.v3_client.delete_role, role_body['id'])
94
95 _, user = self.v3_client.get_user(user_body['id'])
96 _, role = self.v3_client.get_role(role_body['id'])
97 for i in range(2):
98 # Creating project so as to assign role
99 _, project_body = self.v3_client.create_project(
Masayuki Igawa259c1132013-10-31 17:48:44 +0900100 data_utils.rand_name('project-'),
101 description=data_utils.rand_name('project-desc-'))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530102 _, project = self.v3_client.get_project(project_body['id'])
103 # Delete the Project at the end of this method
104 self.addCleanup(self.v3_client.delete_project, project_body['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200105 # Assigning roles to user on project
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530106 self.v3_client.assign_user_role(project['id'],
107 user['id'],
108 role['id'])
109 assigned_project_ids.append(project['id'])
110 resp, body = self.v3_client.list_user_projects(user['id'])
111 self.assertEqual(200, resp.status)
112 for i in body:
113 fetched_project_ids.append(i['id'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +0200114 # verifying the project ids in list
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530115 missing_projects =\
116 [p for p in assigned_project_ids
117 if p not in fetched_project_ids]
118 self.assertEqual(0, len(missing_projects),
119 "Failed to find project %s in fetched list" %
120 ', '.join(m_project for m_project
DennyZhangb432bac2013-09-17 16:24:12 +0000121 in missing_projects))
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +0530122
123
124class UsersV3TestXML(UsersV3TestJSON):
125 _interface = 'xml'