Allow empty description for tenants.
Bug: 1025929 (based on the patch submitted by Ivan Bondarev) * keystoneclient/v2_0/shell.py do_tenant_update(): Update description if it is defined. * keystoneclient/v2_0/tenants.py Token.update(), TokenManager.update(): Update description if it is defined, even if it's empty. * tests/v2_0/test_tenants.py test_update_empty_description(): New test case for empty description. Change-Id: I4c4e93f6bd5d38828685fd55eb1e694f521928e9
This commit is contained in:

committed by
Gerrit Code Review

parent
8ab3c92deb
commit
06916aab53
@@ -140,7 +140,7 @@ def do_tenant_update(kc, args):
|
||||
kwargs = {}
|
||||
if args.name:
|
||||
kwargs.update({'name': args.name})
|
||||
if args.description:
|
||||
if args.description is not None:
|
||||
kwargs.update({'description': args.description})
|
||||
if args.enabled:
|
||||
kwargs.update({'enabled': utils.string_to_bool(args.enabled)})
|
||||
|
@@ -38,7 +38,10 @@ class Tenant(base.Resource):
|
||||
def update(self, name=None, description=None, enabled=None):
|
||||
# Preserve the existing settings; keystone legacy resets these?
|
||||
new_name = name if name else self.name
|
||||
new_description = description if description else self.description
|
||||
if description is not None:
|
||||
new_description = description
|
||||
else:
|
||||
new_description = self.description
|
||||
new_enabled = enabled if enabled is not None else self.enabled
|
||||
|
||||
try:
|
||||
@@ -116,7 +119,7 @@ class TenantManager(base.ManagerWithFind):
|
||||
body['tenant']['name'] = tenant_name
|
||||
if enabled is not None:
|
||||
body['tenant']['enabled'] = enabled
|
||||
if description:
|
||||
if description is not None:
|
||||
body['tenant']['description'] = description
|
||||
# Keystone's API uses a POST rather than a PUT here.
|
||||
return self._create("/tenants/%s" % tenant_id, body, "tenant")
|
||||
|
@@ -218,6 +218,46 @@ class TenantTests(utils.TestCase):
|
||||
self.assertEqual(tenant.description, "I changed you!")
|
||||
self.assertFalse(tenant.enabled)
|
||||
|
||||
def test_update_empty_description(self):
|
||||
req_body = {
|
||||
"tenant": {
|
||||
"id": 4,
|
||||
"name": "tenantX",
|
||||
"description": "",
|
||||
"enabled": False,
|
||||
},
|
||||
}
|
||||
resp_body = {
|
||||
"tenant": {
|
||||
"name": "tenantX",
|
||||
"enabled": False,
|
||||
"id": 4,
|
||||
"description": "",
|
||||
},
|
||||
}
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
"body": json.dumps(resp_body),
|
||||
})
|
||||
|
||||
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
|
||||
'v2.0/tenants/4'),
|
||||
'POST',
|
||||
body=json.dumps(req_body),
|
||||
headers=self.TEST_POST_HEADERS) \
|
||||
.AndReturn((resp, resp['body']))
|
||||
self.mox.ReplayAll()
|
||||
|
||||
tenant = self.client.tenants.update(req_body['tenant']['id'],
|
||||
req_body['tenant']['name'],
|
||||
req_body['tenant']['description'],
|
||||
req_body['tenant']['enabled'])
|
||||
self.assertTrue(isinstance(tenant, tenants.Tenant))
|
||||
self.assertEqual(tenant.id, 4)
|
||||
self.assertEqual(tenant.name, "tenantX")
|
||||
self.assertEqual(tenant.description, "")
|
||||
self.assertFalse(tenant.enabled)
|
||||
|
||||
def test_add_user(self):
|
||||
resp = httplib2.Response({
|
||||
"status": 200,
|
||||
|
Reference in New Issue
Block a user