summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-17 19:06:02 +0000
committerGerrit Code Review <review@openstack.org>2015-03-17 19:06:02 +0000
commitad024b6dcf94f6c838757daad54100eed09bfe86 (patch)
treec1b34ead14c5d776f203326837e5a4f7424c1651
parentf413f138fe3bddc2807f44467237596471812527 (diff)
parent41ab8cf32caf9dccbef91133f51f337680aef9af (diff)
downloadpython-barbicanclient-ad024b6dcf94f6c838757daad54100eed09bfe86.tar.gz
Merge "Added new exception, renamed test, and adjusted test"
-rw-r--r--barbicanclient/exceptions.py22
-rw-r--r--barbicanclient/secrets.py5
-rw-r--r--functionaltests/client/v1/functional/test_secrets.py14
3 files changed, 35 insertions, 6 deletions
diff --git a/barbicanclient/exceptions.py b/barbicanclient/exceptions.py
new file mode 100644
index 0000000..94db9c8
--- /dev/null
+++ b/barbicanclient/exceptions.py
@@ -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
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py
index a92edd1..844ef4a 100644
--- a/barbicanclient/secrets.py
+++ b/barbicanclient/secrets.py
@@ -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
diff --git a/functionaltests/client/v1/functional/test_secrets.py b/functionaltests/client/v1/functional/test_secrets.py
index 552f17a..0966442 100644
--- a/functionaltests/client/v1/functional/test_secrets.py
+++ b/functionaltests/client/v1/functional/test_secrets.py
@@ -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': {