blob: d88cf2eda176152e3ac7657e2b68b61f7fa9d25f [file] [log] [blame]
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +05301# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.common.utils.data_utils import rand_name
19from tempest.test import attr
20from tempest.tests.identity import base
21
22
23class UsersV3TestJSON(base.BaseIdentityAdminTest):
24 _interface = 'json'
25
Giampaolo Lauriaea294952013-05-15 08:52:04 -040026 @attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053027 def test_user_update(self):
28 # Test case to check if updating of user attributes is successful.
29 #Creating first user
30 u_name = rand_name('user-')
31 u_desc = u_name + 'description'
32 u_email = u_name + '@testmail.tm'
33 u_password = rand_name('pass-')
34 resp, user = self.v3_client.create_user(
35 u_name, description=u_desc, password=u_password,
36 email=u_email, enabled=False)
37 # Delete the User at the end of this method
38 self.addCleanup(self.v3_client.delete_user, user['id'])
39 #Creating second project for updation
40 resp, project = self.v3_client.create_project(
41 rand_name('project-'), description=rand_name('project-desc-'))
42 # Delete the Project at the end of this method
43 self.addCleanup(self.v3_client.delete_project, project['id'])
44 #Updating user details with new values
45 u_name2 = rand_name('user2-')
46 u_email2 = u_name2 + '@testmail.tm'
47 u_description2 = u_name2 + ' description'
48 resp, update_user = self.v3_client.update_user(
49 user['id'], name=u_name2, description=u_description2,
50 project_id=project['id'],
51 email=u_email2, enabled=False)
52 #Assert response body of update user.
53 self.assertEqual(200, resp.status)
54 self.assertEqual(u_name2, update_user['name'])
55 self.assertEqual(u_description2, update_user['description'])
56 self.assertEqual(project['id'],
57 update_user['project_id'])
58 self.assertEqual(u_email2, update_user['email'])
59 self.assertEqual('false', str(update_user['enabled']).lower())
60 #GET by id after updation
61 resp, new_user_get = self.v3_client.get_user(user['id'])
62 #Assert response body of GET after updation
63 self.assertEqual(u_name2, new_user_get['name'])
64 self.assertEqual(u_description2, new_user_get['description'])
65 self.assertEqual(project['id'],
66 new_user_get['project_id'])
67 self.assertEqual(u_email2, new_user_get['email'])
68 self.assertEqual('false', str(new_user_get['enabled']).lower())
69
Giampaolo Lauriaea294952013-05-15 08:52:04 -040070 @attr(type='gate')
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053071 def test_list_user_projects(self):
72 #List the projects that a user has access upon
73 assigned_project_ids = list()
74 fetched_project_ids = list()
75 _, u_project = self.v3_client.create_project(
76 rand_name('project-'), description=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'])
rajalakshmi-ganesan7312bb52013-01-29 20:03:42 +053079 #Create a user.
80 u_name = rand_name('user-')
81 u_desc = u_name + 'description'
82 u_email = u_name + '@testmail.tm'
83 u_password = rand_name('pass-')
84 _, 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
90 _, role_body = self.v3_client.create_role(rand_name('role-'))
91 # Delete the Role at the end of this method
92 self.addCleanup(self.v3_client.delete_role, role_body['id'])
93
94 _, user = self.v3_client.get_user(user_body['id'])
95 _, role = self.v3_client.get_role(role_body['id'])
96 for i in range(2):
97 # Creating project so as to assign role
98 _, project_body = self.v3_client.create_project(
99 rand_name('project-'), description=rand_name('project-desc-'))
100 _, project = self.v3_client.get_project(project_body['id'])
101 # Delete the Project at the end of this method
102 self.addCleanup(self.v3_client.delete_project, project_body['id'])
103 #Assigning roles to user on project
104 self.v3_client.assign_user_role(project['id'],
105 user['id'],
106 role['id'])
107 assigned_project_ids.append(project['id'])
108 resp, body = self.v3_client.list_user_projects(user['id'])
109 self.assertEqual(200, resp.status)
110 for i in body:
111 fetched_project_ids.append(i['id'])
112 #verifying the project ids in list
113 missing_projects =\
114 [p for p in assigned_project_ids
115 if p not in fetched_project_ids]
116 self.assertEqual(0, len(missing_projects),
117 "Failed to find project %s in fetched list" %
118 ', '.join(m_project for m_project
119 in missing_projects))
120
121
122class UsersV3TestXML(UsersV3TestJSON):
123 _interface = 'xml'