Added Test Code, doc string, and fixed pip-requiresw

This commit is contained in:
Nachi Ueno
2011-08-22 14:24:37 -07:00
parent b10e17d0eb
commit e65c5f2f57
3 changed files with 33 additions and 2 deletions

View File

@@ -404,9 +404,10 @@ DEFINE_string('root_helper', 'sudo',
'Command prefix to use for running commands as root')
DEFINE_bool('monkey_patch', False,
'Whether to monkey patch')
'Whether to log monkey patching')
DEFINE_list('monkey_patch_modules',
['nova.api.ec2.cloud:nova.notifier.api.notify_decorator',
'nova.compute.api:nova.notifier.api.notify_decorator'],
'Module list representing monkey patched module and decorator')
'Module list representing monkey\
patched module and decorator')

View File

@@ -40,6 +40,14 @@ class BadPriorityException(Exception):
def notify_decorator(name, fn):
""" decorator for notify which is used from utils.monkey_patch()
Parameters:
name - name of the function
function - object of the function
"""
def wrapped_func(*args, **kwarg):
body = {}
body['args'] = []

View File

@@ -134,3 +134,25 @@ class NotifierTestCase(test.TestCase):
self.assertEqual(msg['event_type'], 'error_notification')
self.assertEqual(msg['priority'], 'ERROR')
self.assertEqual(msg['payload']['error'], 'foo')
def test_send_notification_by_decorator(self):
self.notify_called = False
def example_api(arg1, arg2):
return arg1 + arg2
example_api =\
nova.notifier.api.notify_decorator(
'example_api',
example_api)
def mock_notify(cls, *args):
self.notify_called = True
self.stubs.Set(nova.notifier.no_op_notifier, 'notify',
mock_notify)
class Mock(object):
pass
self.assertEqual(3, example_api(1, 2))
self.assertEqual(self.notify_called, True)