summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Diaz <diazjf@us.ibm.com>2015-08-12 13:10:48 -0500
committerFernando Diaz <diazjf@us.ibm.com>2015-08-25 14:58:25 +0000
commit17ed50a9f960bbbabfae194a27f5ad076958248c (patch)
tree3000ff1fff3457b4ff8adbc3acae4a3a07388bd6
parent34256de82d61a7030204a715dd2901dddb46c8e9 (diff)
downloadpython-barbicanclient-17ed50a9f960bbbabfae194a27f5ad076958248c.tar.gz
Add Unit Tests for Store and Update Payload when Payload is zero
Adds Unit Tests for storing and updating a payload that is set to zero. Also updated an exception to give more info. Change-Id: I5a4224b3a10ea64492b57cc6d2c3a5da53f55383
-rw-r--r--barbicanclient/secrets.py2
-rw-r--r--barbicanclient/tests/test_secrets.py26
2 files changed, 26 insertions, 2 deletions
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py
index 2ed41d7..a8f5a4e 100644
--- a/barbicanclient/secrets.py
+++ b/barbicanclient/secrets.py
@@ -336,7 +336,7 @@ class Secret(SecretFormatter):
"""
if not self.payload:
- raise exceptions.PayloadException("Missing Payload")
+ raise exceptions.PayloadException("Invalid or Missing Payload")
if not self.secret_ref:
raise LookupError("Secret is not yet stored.")
diff --git a/barbicanclient/tests/test_secrets.py b/barbicanclient/tests/test_secrets.py
index 91beb8b..4df946e 100644
--- a/barbicanclient/tests/test_secrets.py
+++ b/barbicanclient/tests/test_secrets.py
@@ -18,7 +18,7 @@ import json
from oslo_utils import timeutils
from barbicanclient.tests import test_client
-from barbicanclient import secrets, base
+from barbicanclient import secrets, base, exceptions
class SecretData(object):
@@ -417,6 +417,30 @@ class WhenTestingSecrets(test_client.BaseEntityResource):
self.assertRaises(ValueError, self.manager.get,
**{'secret_ref': '12345'})
+ def test_should_fail_update_zero(self):
+ data = {'secret_ref': self.entity_href}
+ self.responses.post(self.entity_base + '/', json=data)
+
+ secret = self.manager.create()
+ secret.payload = None
+ secret.store()
+
+ self.responses.put(self.entity_href, status_code=204)
+ secret.payload = 0
+
+ # Verify that an error is thrown
+ self.assertRaises(exceptions.PayloadException, secret.update)
+
+ def test_should_fail_store_zero(self):
+ data = {'secret_ref': self.entity_href}
+ self.responses.post(self.entity_base + '/', json=data)
+
+ secret = self.manager.create()
+ secret.name = self.secret.name
+ secret.payload = 0
+
+ self.assertRaises(exceptions.PayloadException, secret.store)
+
def test_should_fail_decrypt_no_content_types(self):
data = self.secret.get_dict(self.entity_href)
self.responses.get(self.entity_href, json=data)