diff --git a/keystoneclient/tests/v3/test_credentials.py b/keystoneclient/tests/v3/test_credentials.py index 50b4a9316..be9903393 100644 --- a/keystoneclient/tests/v3/test_credentials.py +++ b/keystoneclient/tests/v3/test_credentials.py @@ -28,8 +28,28 @@ class CredentialTests(utils.TestCase, utils.CrudTests): def new_ref(self, **kwargs): kwargs = super(CredentialTests, self).new_ref(**kwargs) - kwargs.setdefault('data', uuid.uuid4().hex) + kwargs.setdefault('blob', uuid.uuid4().hex) kwargs.setdefault('project_id', uuid.uuid4().hex) kwargs.setdefault('type', uuid.uuid4().hex) kwargs.setdefault('user_id', uuid.uuid4().hex) return kwargs + + @staticmethod + def _ref_data_not_blob(ref): + ret_ref = ref.copy() + ret_ref['data'] = ref['blob'] + del ret_ref['blob'] + return ret_ref + + def test_create_data_not_blob(self): + # Test create operation with previous, deprecated "data" argument, + # which should be translated into "blob" at the API call level + req_ref = self.new_ref() + api_ref = self._ref_data_not_blob(req_ref) + self.test_create(api_ref, req_ref) + + def test_update_data_not_blob(self): + # Likewise test update operation with data instead of blob argument + req_ref = self.new_ref() + api_ref = self._ref_data_not_blob(req_ref) + self.test_update(api_ref, req_ref) diff --git a/keystoneclient/tests/v3/utils.py b/keystoneclient/tests/v3/utils.py index 182e947c3..3ec35b1e9 100644 --- a/keystoneclient/tests/v3/utils.py +++ b/keystoneclient/tests/v3/utils.py @@ -261,12 +261,16 @@ class CrudTests(object): self.assertQueryStringIs({}) @httpretty.activate - def test_update(self, ref=None): + def test_update(self, ref=None, req_ref=None): ref = ref or self.new_ref() self.stub_entity(httpretty.PATCH, id=ref['id'], entity=ref) - req_ref = ref.copy() + # req_ref argument allows you to specify a different + # signature for the request when the manager does some + # conversion before doing the request (e.g converting + # from datetime object to timestamp string) + req_ref = (req_ref or ref).copy() req_ref.pop('id') returned = self.manager.update(ref['id'], **parameterize(req_ref)) diff --git a/keystoneclient/v3/credentials.py b/keystoneclient/v3/credentials.py index 6403d8d17..35fab1c9c 100644 --- a/keystoneclient/v3/credentials.py +++ b/keystoneclient/v3/credentials.py @@ -33,11 +33,25 @@ class CredentialManager(base.CrudManager): collection_key = 'credentials' key = 'credential' - def create(self, user, type, data, project=None): + def _get_data_blob(self, blob, data): + # Ref bug #1259461, the <= 0.4.1 keystoneclient calling convention was + # to pass "data", but the underlying API expects "blob", so + # support both in the python API for backwards compatibility + if blob is not None: + return blob + elif data is not None: + # FIXME(shardy): Passing data is deprecated. Provide an + # appropriate warning. + return data + else: + raise ValueError( + "Credential requires blob to be specified") + + def create(self, user, type, blob=None, data=None, project=None): return super(CredentialManager, self).create( user_id=base.getid(user), type=type, - data=data, + blob=self._get_data_blob(blob, data), project_id=base.getid(project)) def get(self, credential): @@ -47,12 +61,13 @@ class CredentialManager(base.CrudManager): def list(self): return super(CredentialManager, self).list() - def update(self, credential, user, type=None, data=None, project=None): + def update(self, credential, user, type=None, blob=None, data=None, + project=None): return super(CredentialManager, self).update( credential_id=base.getid(credential), user_id=base.getid(user), type=type, - data=data, + blob=self._get_data_blob(blob, data), project_id=base.getid(project)) def delete(self, credential):