summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChellygel <chelsea.winfree@gmail.com>2015-03-17 03:06:44 -0500
committerChellygel <chelsea.winfree@gmail.com>2015-03-17 16:27:39 -0500
commit2a27f57f5928bc414d7b88035abc1d2c9c4e94a1 (patch)
treebef39ad585a3bb68aa7d72f796b2d96fb62bcd01
parent6e7f0e963036e59657e700dd1bbb60d10e1c6edf (diff)
downloadpython-barbicanclient-2a27f57f5928bc414d7b88035abc1d2c9c4e94a1.tar.gz
Fixes tests on invalid payload secret creation and adds new exception
Adding a new exception to cover the case of a payload being set to a list or int. Moved the zero case to the no payload tests as well. Functional test now verifies new exception is raised with bad types. Change-Id: Id026fd7a2004c6c30502a30bca96b6116d4bc9cf
-rw-r--r--barbicanclient/exceptions.py4
-rw-r--r--barbicanclient/secrets.py3
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py22
3 files changed, 18 insertions, 11 deletions
diff --git a/barbicanclient/exceptions.py b/barbicanclient/exceptions.py
index 94db9c8..e032de4 100644
--- a/barbicanclient/exceptions.py
+++ b/barbicanclient/exceptions.py
@@ -20,3 +20,7 @@ class BarbicanException(Exception):
class NoPayloadException(BarbicanException):
pass
+
+
+class InvalidPayloadException(BarbicanException):
+ pass
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py
index 0286de0..0f50317 100644
--- a/barbicanclient/secrets.py
+++ b/barbicanclient/secrets.py
@@ -251,6 +251,7 @@ class Secret(SecretFormatter):
in Barbican until this method is called.
:raises: NoPayloadException
+ :raises: InvalidPayloadException
"""
secret_dict = {
'name': self.name,
@@ -262,6 +263,8 @@ class Secret(SecretFormatter):
if not self.payload:
raise exceptions.NoPayloadException
+ if not isinstance(self.payload, (six.text_type, six.binary_type)):
+ raise exceptions.InvalidPayloadException
if self.payload_content_type:
"""
Setting the payload_content_type and payload_content_encoding
diff --git a/functionaltests/client/v1/functional/test_secrets.py b/functionaltests/client/v1/functional/test_secrets.py
index 0966442..b1b28cf 100644
--- a/functionaltests/client/v1/functional/test_secrets.py
+++ b/functionaltests/client/v1/functional/test_secrets.py
@@ -273,29 +273,29 @@ class SecretsTestCase(base.TestCase):
self.assertEqual(test_model.payload, get_resp.payload)
@utils.parameterized_dataset({
- 'array': [['boom']],
- 'int': [123],
- 'zero': [0]
+ 'list': [['boom']],
+ 'int': [123]
})
@testcase.attr('negative')
- def test_secret_create_defaults_invalid_payload_http_err(self, payload):
- """Covers creating secrets with various invalid payloads.
+ def test_secret_create_with_invalid_payload_(self, payload):
+ """Covers attempting to create secret with invalid payload types
- These requests will error with 400 and are will make a request to
- the server.
+ Tests the negative cases of invalid types (list and int).
"""
test_model = self.behaviors.create_secret(
secret_create_defaults_data)
test_model.payload = payload
- e = self.assertRaises(Exception, self.behaviors.store_secret,
- test_model)
-
- self.assertEqual(e.http_status, 400)
+ self.assertRaises(
+ exceptions.InvalidPayloadException,
+ self.behaviors.store_secret,
+ test_model
+ )
@utils.parameterized_dataset({
'empty': [''],
'none': [None],
+ 'zero': [0]
})
@testcase.attr('negative')
def test_secret_with_no_payload_exception(self, payload):