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
This commit is contained in:
Chellygel
2015-03-17 03:06:44 -05:00
parent 6e7f0e9630
commit 2a27f57f59
3 changed files with 18 additions and 11 deletions

View File

@@ -20,3 +20,7 @@ class BarbicanException(Exception):
class NoPayloadException(BarbicanException):
pass
class InvalidPayloadException(BarbicanException):
pass

View File

@@ -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

View File

@@ -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):