Merge "Added new exception, renamed test, and adjusted test"

This commit is contained in:
Jenkins
2015-03-17 19:06:02 +00:00
committed by Gerrit Code Review
3 changed files with 35 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
# Copyright (c) 2015 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class BarbicanException(Exception):
pass
class NoPayloadException(BarbicanException):
pass

View File

@@ -20,6 +20,7 @@ from oslo_utils.timeutils import parse_isotime
import six
from barbicanclient import base
from barbicanclient import exceptions
from barbicanclient import formatter
@@ -248,6 +249,8 @@ class Secret(SecretFormatter):
"""
Stores the Secret in Barbican. New Secret objects are not persisted
in Barbican until this method is called.
:raises: NoPayloadException
"""
secret_dict = {
'name': self.name,
@@ -257,6 +260,8 @@ class Secret(SecretFormatter):
'expiration': self.expiration
}
if not self.payload:
raise exceptions.NoPayloadException
if self.payload_content_type:
"""
Setting the payload_content_type and payload_content_encoding

View File

@@ -20,6 +20,8 @@ from functionaltests.client.v1.behaviors import secret_behaviors
from functionaltests import utils
from testtools import testcase
from barbicanclient import exceptions
secret_create_defaults_data = {
"name": "AES key",
"expiration": "2018-02-28T19:14:44.180394",
@@ -296,7 +298,7 @@ class SecretsTestCase(base.TestCase):
'none': [None],
})
@testcase.attr('negative')
def test_secret_create_defaults_invalid_payload(self, payload):
def test_secret_with_no_payload_exception(self, payload):
"""Covers creating secrets with various invalid payloads.
These requests will fail with a value error before the request to the
@@ -305,11 +307,11 @@ class SecretsTestCase(base.TestCase):
secret_create_defaults_data)
test_model.payload = payload
e = self.assertRaises(ValueError, self.behaviors.store_secret,
test_model)
self.assertIn('Payload incorrectly specified.',
e.message)
self.assertRaises(
exceptions.NoPayloadException,
self.behaviors.store_secret,
test_model
)
@utils.parameterized_dataset({
'negative_five_long_expire': {