Raise ManagedObjectNotFoundError in MockKeyManager
Currently the MockKeyManager raises KeyError when a key is not found for a get() or delete() but a real key manager raises ManagedObjectNotFoundError in the case of not found [1][2]. This updates the MockKeyManager to raise the same exception as a real key manager so that projects using it in tests will be able to test their handling of "not found" scenarios properly. [1]a662b30764/castellan/key_manager/barbican_key_manager.py (L617)
[2]a662b30764/castellan/key_manager/barbican_key_manager.py (L644)
Change-Id: I3184a229f6690854dda1edc12e74bb483b47a057
This commit is contained in:
parent
e4c44a460d
commit
4925356be6
@ -178,7 +178,11 @@ class MockKeyManager(key_manager.KeyManager):
|
||||
if context is None:
|
||||
raise exception.Forbidden()
|
||||
|
||||
obj = copy.deepcopy(self.keys[managed_object_id])
|
||||
try:
|
||||
obj = copy.deepcopy(self.keys[managed_object_id])
|
||||
except KeyError:
|
||||
raise exception.ManagedObjectNotFoundError()
|
||||
|
||||
if metadata_only:
|
||||
if hasattr(obj, "_key"):
|
||||
obj._key = None
|
||||
@ -197,7 +201,10 @@ class MockKeyManager(key_manager.KeyManager):
|
||||
if context is None:
|
||||
raise exception.Forbidden()
|
||||
|
||||
del self.keys[managed_object_id]
|
||||
try:
|
||||
del self.keys[managed_object_id]
|
||||
except KeyError:
|
||||
raise exception.ManagedObjectNotFoundError()
|
||||
|
||||
def add_consumer(self, context, managed_object_id, consumer_data):
|
||||
if context is None:
|
||||
|
@ -201,22 +201,26 @@ class MockKeyManagerTestCase(test_key_mgr.KeyManagerTestCase):
|
||||
self.key_mgr.get, None, None)
|
||||
|
||||
def test_get_unknown_key(self):
|
||||
self.assertRaises(KeyError, self.key_mgr.get, self.context, None)
|
||||
self.assertRaises(
|
||||
exception.ManagedObjectNotFoundError, self.key_mgr.get,
|
||||
self.context, None)
|
||||
|
||||
def test_delete_key(self):
|
||||
key_id = self.key_mgr.create_key(self.context)
|
||||
self.key_mgr.delete(self.context, key_id)
|
||||
|
||||
self.assertRaises(KeyError, self.key_mgr.get, self.context,
|
||||
key_id)
|
||||
self.assertRaises(
|
||||
exception.ManagedObjectNotFoundError, self.key_mgr.get,
|
||||
self.context, key_id)
|
||||
|
||||
def test_delete_null_context(self):
|
||||
self.assertRaises(exception.Forbidden,
|
||||
self.key_mgr.delete, None, None)
|
||||
|
||||
def test_delete_unknown_key(self):
|
||||
self.assertRaises(KeyError, self.key_mgr.delete, self.context,
|
||||
None)
|
||||
self.assertRaises(
|
||||
exception.ManagedObjectNotFoundError, self.key_mgr.delete,
|
||||
self.context, None)
|
||||
|
||||
def test_list_null_context(self):
|
||||
self.assertRaises(exception.Forbidden, self.key_mgr.list, None)
|
||||
|
Loading…
Reference in New Issue
Block a user