Make identity v2 user_client use **kwargs

As we discussed on
http://lists.openstack.org/pipermail/openstack-dev/2015-July/068864.html
All http POST/PUT methods need to contain **kwargs as their arguments.
This patch makes identity v2 user_client use **kwargs.

Also adding some doc link.

Partially implements blueprint consistent-service-method-names

Change-Id: I058e74a205ff9223113ad9fed8be61e6b66e7045
This commit is contained in:
ghanshyam 2016-06-15 14:50:41 +09:00 committed by Ghanshyam Mann
parent 6ce3921969
commit e1c6c1c54e
8 changed files with 124 additions and 72 deletions

View File

@ -30,8 +30,10 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
self.data.tenants.append(tenant)
# second:create a user
user = self.users_client.create_user(user_name, user_password,
tenant['id'], '')['user']
user = self.users_client.create_user(name=user_name,
password=user_password,
tenantId=tenant['id'],
email='')['user']
self.data.users.append(user)
# then get a token for the user
body = self.token_client.auth(user_name,
@ -62,8 +64,10 @@ class TokensTestJSON(base.BaseIdentityV2AdminTest):
user_password = data_utils.rand_password()
tenant_id = None # No default tenant so will get unscoped token.
email = ''
user = self.users_client.create_user(user_name, user_password,
tenant_id, email)['user']
user = self.users_client.create_user(name=user_name,
password=user_password,
tenantId=tenant_id,
email=email)['user']
self.data.users.append(user)
# Create a couple tenants.

View File

@ -36,9 +36,10 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
def test_create_user(self):
# Create a user
self.data.setup_test_tenant()
user = self.users_client.create_user(self.alt_user, self.alt_password,
self.data.tenant['id'],
self.alt_email)['user']
user = self.users_client.create_user(name=self.alt_user,
password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)['user']
self.data.users.append(user)
self.assertEqual(self.alt_user, user['name'])
@ -47,9 +48,10 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
# Create a user with enabled : False
self.data.setup_test_tenant()
name = data_utils.rand_name('test_user')
user = self.users_client.create_user(name, self.alt_password,
self.data.tenant['id'],
self.alt_email,
user = self.users_client.create_user(name=name,
password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email,
enabled=False)['user']
self.data.users.append(user)
self.assertEqual(name, user['name'])
@ -61,9 +63,10 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
# Test case to check if updating of user attributes is successful.
test_user = data_utils.rand_name('test_user')
self.data.setup_test_tenant()
user = self.users_client.create_user(test_user, self.alt_password,
self.data.tenant['id'],
self.alt_email)['user']
user = self.users_client.create_user(name=test_user,
password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)['user']
# Delete the User at the end of this method
self.addCleanup(self.users_client.delete_user, user['id'])
# Updating user details with new values
@ -87,9 +90,10 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
# Delete a user
test_user = data_utils.rand_name('test_user')
self.data.setup_test_tenant()
user = self.users_client.create_user(test_user, self.alt_password,
self.data.tenant['id'],
self.alt_email)['user']
user = self.users_client.create_user(name=test_user,
password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)['user']
self.users_client.delete_user(user['id'])
@test.idempotent_id('aca696c3-d645-4f45-b728-63646045beb1')
@ -139,16 +143,18 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
fetched_user_ids = list()
password1 = data_utils.rand_password()
alt_tenant_user1 = data_utils.rand_name('tenant_user1')
user1 = self.users_client.create_user(alt_tenant_user1, password1,
self.data.tenant['id'],
'user1@123')['user']
user1 = self.users_client.create_user(name=alt_tenant_user1,
password=password1,
tenantId=self.data.tenant['id'],
email='user1@123')['user']
user_ids.append(user1['id'])
self.data.users.append(user1)
password2 = data_utils.rand_password()
alt_tenant_user2 = data_utils.rand_name('tenant_user2')
user2 = self.users_client.create_user(alt_tenant_user2, password2,
self.data.tenant['id'],
'user2@123')['user']
user2 = self.users_client.create_user(name=alt_tenant_user2,
password=password2,
tenantId=self.data.tenant['id'],
email='user2@123')['user']
user_ids.append(user2['id'])
self.data.users.append(user2)
# List of users for the respective tenant ID
@ -180,9 +186,11 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest):
alt_user2 = data_utils.rand_name('second_user')
alt_password2 = data_utils.rand_password()
second_user = self.users_client.create_user(alt_user2, alt_password2,
self.data.tenant['id'],
'user2@123')['user']
second_user = self.users_client.create_user(
name=alt_user2,
password=alt_password2,
tenantId=self.data.tenant['id'],
email='user2@123')['user']
user_ids.append(second_user['id'])
self.data.users.append(second_user)
role = self.roles_client.assign_user_role(tenant['id'],

View File

@ -35,9 +35,9 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
self.data.setup_test_tenant()
self.assertRaises(lib_exc.Forbidden,
self.non_admin_users_client.create_user,
self.alt_user, self.alt_password,
self.data.tenant['id'],
self.alt_email)
name=self.alt_user, password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)
@test.attr(type=['negative'])
@test.idempotent_id('d80d0c2f-4514-4d1e-806d-0930dfc5a187')
@ -45,8 +45,9 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
# User with an empty name should not be created
self.data.setup_test_tenant()
self.assertRaises(lib_exc.BadRequest, self.users_client.create_user,
'', self.alt_password, self.data.tenant['id'],
self.alt_email)
name='', password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)
@test.attr(type=['negative'])
@test.idempotent_id('7704b4f3-3b75-4b82-87cc-931d41c8f780')
@ -54,8 +55,9 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
# Length of user name filed should be restricted to 255 characters
self.data.setup_test_tenant()
self.assertRaises(lib_exc.BadRequest, self.users_client.create_user,
'a' * 256, self.alt_password,
self.data.tenant['id'], self.alt_email)
name='a' * 256, password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)
@test.attr(type=['negative'])
@test.idempotent_id('57ae8558-120c-4723-9308-3751474e7ecf')
@ -63,16 +65,20 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
# Duplicate user should not be created
self.data.setup_test_user()
self.assertRaises(lib_exc.Conflict, self.users_client.create_user,
self.data.user['name'], self.data.user_password,
self.data.tenant['id'], self.data.user['email'])
name=self.data.user['name'],
password=self.data.user_password,
tenantId=self.data.tenant['id'],
email=self.data.user['email'])
@test.attr(type=['negative'])
@test.idempotent_id('0132cc22-7c4f-42e1-9e50-ac6aad31d59a')
def test_create_user_for_non_existent_tenant(self):
# Attempt to create a user in a non-existent tenant should fail
self.assertRaises(lib_exc.NotFound, self.users_client.create_user,
self.alt_user, self.alt_password, '49ffgg99999',
self.alt_email)
name=self.alt_user,
password=self.alt_password,
tenantId='49ffgg99999',
email=self.alt_email)
@test.attr(type=['negative'])
@test.idempotent_id('55bbb103-d1ae-437b-989b-bcdf8175c1f4')
@ -88,8 +94,9 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
self.addCleanup(self.client.auth_provider.clear_auth)
self.assertRaises(lib_exc.Unauthorized, self.users_client.create_user,
self.alt_user, self.alt_password,
self.data.tenant['id'], self.alt_email)
name=self.alt_user, password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email)
@test.attr(type=['negative'])
@test.idempotent_id('23a2f3da-4a1a-41da-abdd-632328a861ad')
@ -98,9 +105,9 @@ class UsersNegativeTestJSON(base.BaseIdentityV2AdminTest):
self.data.setup_test_tenant()
name = data_utils.rand_name('test_user')
self.assertRaises(lib_exc.BadRequest, self.users_client.create_user,
name, self.alt_password,
self.data.tenant['id'],
self.alt_email, enabled=3)
name=name, password=self.alt_password,
tenantId=self.data.tenant['id'],
email=self.alt_email, enabled=3)
@test.attr(type=['negative'])
@test.idempotent_id('3d07e294-27a0-4144-b780-a2a1bf6fee19')

View File

@ -215,11 +215,10 @@ class BaseDataGenerator(object):
self.domains = []
def _create_test_user(self, **kwargs):
username = data_utils.rand_name('test_user')
self.user_password = data_utils.rand_password()
self.user = self.users_client.create_user(
username, password=self.user_password,
email=username + '@testmail.tm', **kwargs)['user']
password=self.user_password,
**kwargs)['user']
self.users.append(self.user)
def setup_test_role(self):
@ -256,7 +255,10 @@ class DataGeneratorV2(BaseDataGenerator):
def setup_test_user(self):
"""Set up a test user."""
self.setup_test_tenant()
self._create_test_user(tenant_id=self.tenant['id'])
username = data_utils.rand_name('test_user')
email = username + '@testmail.tm'
self._create_test_user(name=username, email=email,
tenantId=self.tenant['id'])
def setup_test_tenant(self):
"""Set up a test tenant."""
@ -271,7 +273,10 @@ class DataGeneratorV3(BaseDataGenerator):
def setup_test_user(self):
"""Set up a test user."""
self.setup_test_project()
self._create_test_user(project_id=self.project['id'])
username = data_utils.rand_name('test_user')
email = username + '@testmail.tm'
self._create_test_user(user_name=username, email=email,
project_id=self.project['id'])
def setup_test_project(self):
"""Set up a test project."""

View File

@ -391,8 +391,9 @@ def create_users(users):
% u['name'])
except lib_exc.NotFound:
admin.users.create_user(
u['name'], u['pass'], tenant['id'],
"%s@%s" % (u['name'], tenant['id']),
name=u['name'], password=u['pass'],
tenantId=tenant['id'],
email="%s@%s" % (u['name'], tenant['id']),
enabled=True)

View File

@ -40,8 +40,9 @@ class CredsClient(object):
self.roles_client = roles_client
def create_user(self, username, password, project, email):
user = self.users_client.create_user(
username, password, project['id'], email)
params = self._create_user_params(username, password,
project['id'], email)
user = self.users_client.create_user(**params)
if 'user' in user:
user = user['user']
return user
@ -101,6 +102,13 @@ class V2CredsClient(CredsClient):
users_client,
roles_client)
def _create_user_params(self, username, password, project_id, email):
params = {'name': username,
'password': password,
'tenantId': project_id,
'email': email}
return params
def create_project(self, name, description):
tenant = self.projects_client.create_tenant(
name=name, description=description)['tenant']
@ -143,6 +151,13 @@ class V3CredsClient(CredsClient):
msg = "Requested domain %s could not be found" % domain_name
raise lib_exc.InvalidCredentials(msg)
def _create_user_params(self, username, password, project_id, email):
params = {'user_name': username,
'password': password,
'project_id': project_id,
'email': email}
return params
def create_project(self, name, description):
project = self.projects_client.create_project(
name=name, description=description,

View File

@ -11,6 +11,7 @@
# under the License.
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib
from tempest.lib.common import rest_client
@ -18,18 +19,13 @@ from tempest.lib.common import rest_client
class UsersClient(rest_client.RestClient):
api_version = "v2.0"
def create_user(self, name, password, tenant_id, email, **kwargs):
"""Create a user."""
post_body = {
'name': name,
'password': password,
'email': email
}
if tenant_id is not None:
post_body['tenantId'] = tenant_id
if kwargs.get('enabled') is not None:
post_body['enabled'] = kwargs.get('enabled')
post_body = json.dumps({'user': post_body})
def create_user(self, **kwargs):
"""Create a user.
Available params: see http://developer.openstack.org/
api-ref-identity-admin-v2.html#admin-createUser
"""
post_body = json.dumps({'user': kwargs})
resp, body = self.post('users', post_body)
self.expected_success(200, resp.status)
body = json.loads(body)
@ -48,21 +44,36 @@ class UsersClient(rest_client.RestClient):
return rest_client.ResponseBody(resp, body)
def show_user(self, user_id):
"""GET a user."""
"""GET a user.
Available params: see http://developer.openstack.org/
api-ref-identity-admin-v2.html#admin-showUser
"""
resp, body = self.get("users/%s" % user_id)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def delete_user(self, user_id):
"""Delete a user."""
"""Delete a user.
Available params: see http://developer.openstack.org/
api-ref-identity-admin-v2.html#admin-deleteUser
"""
resp, body = self.delete("users/%s" % user_id)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def list_users(self):
"""Get the list of users."""
resp, body = self.get("users")
def list_users(self, **params):
"""Get the list of users.
Available params: see http://developer.openstack.org/
api-ref-identity-admin-v2.html#admin-listUsers
"""
url = "users"
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)

View File

@ -120,11 +120,12 @@ class TestCreateResources(JavelinUnitTest):
fake_tenant_id = self.fake_object['tenant']['id']
fake_email = "%s@%s" % (self.fake_object['user'], fake_tenant_id)
mocked_function = self.fake_client.users.create_user
mocked_function.assert_called_once_with(self.fake_object['name'],
self.fake_object['password'],
fake_tenant_id,
fake_email,
enabled=True)
mocked_function.assert_called_once_with(
name=self.fake_object['name'],
password=self.fake_object['password'],
tenantId=fake_tenant_id,
email=fake_email,
enabled=True)
def test_create_user_missing_tenant(self):
self.useFixture(mockpatch.Patch(