summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave McCowan <dmccowan@cisco.com>2015-10-05 10:44:40 -0400
committerDave McCowan <dmccowan@cisco.com>2015-10-05 10:44:40 -0400
commit020e24061b43c1af531bab2348c267bc9f708b31 (patch)
treed09aa2525e6e64d0a966645b7533fbdf420c248a
parent3830d934e938f0b4c8676995b4e0cc20249f12f6 (diff)
downloadpython-barbicanclient-020e24061b43c1af531bab2348c267bc9f708b31.tar.gz
Initialize optional attributes in CA object
When executing "barbican ca list", the client throws an attribute error if a CA does not contain a meta description field. This field is optional. This fix initializes the _description attribute to None to prevent the error. Change-Id: Ic861fe67c59c5109c0f09db46ad229a789d2e510 Closes-bug: #1502928
-rw-r--r--barbicanclient/cas.py2
-rw-r--r--barbicanclient/tests/test_cas.py32
2 files changed, 28 insertions, 6 deletions
diff --git a/barbicanclient/cas.py b/barbicanclient/cas.py
index b4a66d5..5fa3288 100644
--- a/barbicanclient/cas.py
+++ b/barbicanclient/cas.py
@@ -136,6 +136,8 @@ class CA(CAFormatter):
def _fill_from_data(self, meta=None, expiration=None,
plugin_name=None, plugin_ca_id=None, created=None,
updated=None, status=None, creator_id=None):
+ self._name = None
+ self._description = None
if meta:
for s in meta:
key = list(s.keys())[0]
diff --git a/barbicanclient/tests/test_cas.py b/barbicanclient/tests/test_cas.py
index 2b32e12..1a4961e 100644
--- a/barbicanclient/tests/test_cas.py
+++ b/barbicanclient/tests/test_cas.py
@@ -19,9 +19,9 @@ from barbicanclient import cas
class CAData(object):
- def __init__(self):
+ def __init__(self, description=u'Test CA description'):
self.name = u'Test CA'
- self.description = u'Test CA description'
+ self.description = description
self.plugin_name = u'Test CA Plugin'
self.plugin_ca_id = 'plugin_uuid'
@@ -29,10 +29,10 @@ class CAData(object):
self.expiration = str(now)
self.created = str(now)
- self.meta = [
- {'name': self.name},
- {'description': self.description}
- ]
+ self.meta = []
+ self.meta.append({'name': self.name})
+ if self.description:
+ self.meta.append({'description': self.description})
self.ca_dict = {'meta': self.meta,
'status': u'ACTIVE',
@@ -111,3 +111,23 @@ class WhenTestingCAs(test_client.BaseEntityResource):
def test_should_fail_get_invalid_ca(self):
self.assertRaises(ValueError, self.manager.get,
**{'ca_ref': '12345'})
+
+ def test_should_get_ca_that_has_no_meta_description(self):
+ self.ca = CAData(description=None)
+
+ data = self.ca.get_dict(self.entity_href)
+ m = self.responses.get(self.entity_href, json=data)
+
+ ca = self.manager.get(ca_ref=self.entity_href)
+ self.assertIsInstance(ca, cas.CA)
+ self.assertEqual(self.entity_href, ca._ca_ref)
+
+ # Verify GET wasn't called yet
+ self.assertFalse(m.called)
+
+ # Get description from CA, check it is None
+ self.assertIsNone(self.ca.description)
+ self.assertIsNone(ca.description)
+
+ # Verify the correct URL was used to make the GET call
+ self.assertEqual(self.entity_href, m.last_request.url)