magnum/magnum/tests/common/test_exception.py

213 lines
8.1 KiB
Python

# 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.
from magnum.common import exception
from magnum.openstack.common._i18n import _
from magnum.tests import base
class TestMagnumException(exception.MagnumException):
message = _("templated %(name)s")
class TestException(base.BaseTestCase):
def setUp(self):
super(TestException, self).setUp()
def raise_(self, ex):
raise ex
def test_message_is_templated(self):
ex = TestMagnumException(name="NAME")
self.assertEqual(ex.message, "templated NAME")
def test_ObjectNotFound(self):
self.assertRaises(exception.ObjectNotFound,
lambda: self.raise_(exception.ObjectNotFound()))
def test_ObjectNotUnique(self):
self.assertRaises(exception.ObjectNotUnique,
lambda: self.raise_(exception.ObjectNotUnique()))
def test_ResourceNotFound(self):
self.assertRaises(exception.ResourceNotFound,
lambda: self.raise_(exception.ResourceNotFound()))
def test_ResourceExists(self):
self.assertRaises(exception.ResourceExists,
lambda: self.raise_(exception.ResourceExists()))
def test_AuthorizationFailure(self):
self.assertRaises(exception.AuthorizationFailure,
lambda: self.raise_(exception.AuthorizationFailure()))
def test_UnsupportedObjectError(self):
self.assertRaises(exception.UnsupportedObjectError,
lambda: self.raise_(exception.UnsupportedObjectError()))
def test_IncompatibleObjectVersion(self):
self.assertRaises(exception.IncompatibleObjectVersion,
lambda: self.raise_(exception.IncompatibleObjectVersion()))
def test_OrphanedObjectError(self):
self.assertRaises(exception.OrphanedObjectError,
lambda: self.raise_(exception.OrphanedObjectError()))
def test_Invalid(self):
self.assertRaises(exception.Invalid,
lambda: self.raise_(exception.Invalid()))
def test_InvalidUUID(self):
self.assertRaises(exception.InvalidUUID,
lambda: self.raise_(exception.InvalidUUID()))
def test_InvalidIdentity(self):
self.assertRaises(exception.InvalidIdentity,
lambda: self.raise_(exception.InvalidIdentity()))
def test_HTTPNotFound(self):
self.assertRaises(exception.HTTPNotFound,
lambda: self.raise_(exception.HTTPNotFound()))
def test_Conflict(self):
self.assertRaises(exception.Conflict,
lambda: self.raise_(exception.Conflict()))
def test_InvalidState(self):
self.assertRaises(exception.InvalidState,
lambda: self.raise_(exception.InvalidState()))
def test_InvalidParameterValue(self):
self.assertRaises(exception.InvalidParameterValue,
lambda: self.raise_(exception.InvalidParameterValue()))
def test_InstanceAssociated(self):
self.assertRaises(exception.InstanceAssociated,
lambda: self.raise_(exception.InstanceAssociated()))
def test_InstanceNotFound(self):
self.assertRaises(exception.InstanceNotFound,
lambda: self.raise_(exception.InstanceNotFound()))
def test_PatchError(self):
self.assertRaises(exception.PatchError,
lambda: self.raise_(exception.PatchError()))
def test_NotAuthorized(self):
self.assertRaises(exception.NotAuthorized,
lambda: self.raise_(exception.NotAuthorized()))
def test_OperationNotPermitted(self):
self.assertRaises(exception.OperationNotPermitted,
lambda: self.raise_(exception.OperationNotPermitted()))
def test_InvalidMAC(self):
self.assertRaises(exception.InvalidMAC,
lambda: self.raise_(exception.InvalidMAC()))
def test_SSHConnectFailed(self):
self.assertRaises(exception.SSHConnectFailed,
lambda: self.raise_(exception.SSHConnectFailed()))
def test_FileSystemNotSupported(self):
self.assertRaises(exception.FileSystemNotSupported,
lambda: self.raise_(exception.FileSystemNotSupported()))
def test_BayNotFound(self):
self.assertRaises(exception.BayNotFound,
lambda: self.raise_(exception.BayNotFound()))
def test_BayAssociated(self):
self.assertRaises(exception.BayAssociated,
lambda: self.raise_(exception.BayAssociated()))
def test_BayAlreadyExists(self):
self.assertRaises(exception.BayAlreadyExists,
lambda: self.raise_(exception.BayAlreadyExists()))
def test_BayLocked(self):
self.assertRaises(exception.BayLocked,
lambda: self.raise_(exception.BayLocked()))
def test_BayNotLocked(self):
self.assertRaises(exception.BayNotLocked,
lambda: self.raise_(exception.BayNotLocked()))
def test_BayModelNotFound(self):
self.assertRaises(exception.BayModelNotFound,
lambda: self.raise_(exception.BayModelNotFound()))
def test_BayModelAlreadyExists(self):
self.assertRaises(exception.BayModelAlreadyExists,
lambda: self.raise_(exception.BayModelAlreadyExists()))
def test_ContainerNotFound(self):
self.assertRaises(exception.ContainerNotFound,
lambda: self.raise_(exception.ContainerNotFound()))
def test_ContainerAssociated(self):
self.assertRaises(exception.ContainerAssociated,
lambda: self.raise_(exception.ContainerAssociated()))
def test_ContainerAlreadyExists(self):
self.assertRaises(exception.ContainerAlreadyExists,
lambda: self.raise_(exception.ContainerAlreadyExists()))
def test_ContainerLocked(self):
self.assertRaises(exception.ContainerLocked,
lambda: self.raise_(exception.ContainerLocked()))
def test_ContainerNotLocked(self):
self.assertRaises(exception.ContainerNotLocked,
lambda: self.raise_(exception.ContainerNotLocked()))
def test_PodNotFound(self):
self.assertRaises(exception.PodNotFound,
lambda: self.raise_(exception.PodNotFound()))
def test_PodAssociated(self):
self.assertRaises(exception.PodAssociated,
lambda: self.raise_(exception.PodAssociated()))
def test_PodAlreadyExists(self):
self.assertRaises(exception.PodAlreadyExists,
lambda: self.raise_(exception.PodAlreadyExists()))
def test_PodLocked(self):
self.assertRaises(exception.PodLocked,
lambda: self.raise_(exception.PodLocked()))
def test_PodNotLocked(self):
self.assertRaises(exception.PodNotLocked,
lambda: self.raise_(exception.PodNotLocked()))
def test_ServiceNotFound(self):
self.assertRaises(exception.ServiceNotFound,
lambda: self.raise_(exception.ServiceNotFound()))
def test_ServiceAssociated(self):
self.assertRaises(exception.ServiceAssociated,
lambda: self.raise_(exception.ServiceAssociated()))
def test_ServiceAlreadyExists(self):
self.assertRaises(exception.ServiceAlreadyExists,
lambda: self.raise_(exception.ServiceAlreadyExists()))
def test_ServiceLocked(self):
self.assertRaises(exception.ServiceLocked,
lambda: self.raise_(exception.ServiceLocked()))
def test_ServiceNotLocked(self):
self.assertRaises(exception.ServiceNotLocked,
lambda: self.raise_(exception.ServiceNotLocked()))