Merge "Allow users to set periodic notifications on all notification types"

This commit is contained in:
Zuul 2020-04-18 12:50:58 +00:00 committed by Gerrit Code Review
commit 557fd9cf06
3 changed files with 13 additions and 32 deletions

View File

@ -98,21 +98,12 @@ class TestNotificationsShellV2(base.BaseTestCase):
self._patch_test(mc, args, data)
@mock.patch('monascaclient.osc.migration.make_client')
def test_bad_notifications_patch(self, mc):
mc.return_value = c = FakeV2Client()
id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
raw_args = ('{0} --type EMAIL --address john.doe@hpe.com '
'--period 60').format(id_str).split(' ')
name, cmd_clazz = migr.create_command_class('do_notification_patch',
shell)
cmd = cmd_clazz(mock.Mock(), mock.Mock())
parser = cmd.get_parser(name)
parsed_args = parser.parse_args(raw_args)
cmd.run(parsed_args)
c.notifications.patch.assert_not_called()
def test_good_notifications_patch_recurring_email(self, mc):
args = '--type EMAIL --address john.doe@hpe.com --period 60'
data = {'type': 'EMAIL',
'address': 'john.doe@hpe.com',
'period': 60}
self._patch_test(mc, args, data)
@mock.patch('monascaclient.osc.migration.make_client')
def test_good_notifications_update(self, mc):

View File

@ -554,13 +554,6 @@ def do_metric_statistics(mc, args):
formatters=formatters)
def _validate_notification_period(period, notification_type):
if notification_type != 'WEBHOOK' and period != 0:
print("Invalid period, can only be non zero for webhooks")
return False
return True
@utils.arg('name', metavar='<NOTIFICATION_NAME>',
help='Name of the notification to create.')
@utils.arg('type', metavar='<TYPE>',
@ -568,7 +561,7 @@ def _validate_notification_period(period, notification_type):
@utils.arg('address', metavar='<ADDRESS>',
help='A valid EMAIL Address, URL, or SERVICE KEY.')
@utils.arg('--period', metavar='<PERIOD>', type=int, default=0,
help='A period for the notification method. Can only be non zero with webhooks')
help='A period for the notification method.')
def do_notification_create(mc, args):
'''Create notification.'''
@ -577,8 +570,6 @@ def do_notification_create(mc, args):
fields['type'] = args.type
fields['address'] = args.address
if args.period:
if not _validate_notification_period(args.period, args.type.upper()):
return
fields['period'] = args.period
try:
notification = mc.notifications.create(**fields)
@ -696,7 +687,7 @@ def do_notification_delete(mc, args):
@utils.arg('address', metavar='<ADDRESS>',
help='A valid EMAIL Address, URL, or SERVICE KEY.')
@utils.arg('period', metavar='<PERIOD>', type=int,
help='A period for the notification method. Can only be non zero with webhooks')
help='A period for the notification method.')
def do_notification_update(mc, args):
'''Update notification.'''
fields = {}
@ -705,8 +696,6 @@ def do_notification_update(mc, args):
fields['type'] = args.type
fields['address'] = args.address
if not _validate_notification_period(args.period, args.type.upper()):
return
fields['period'] = args.period
try:
notification = mc.notifications.update(**fields)
@ -725,7 +714,7 @@ def do_notification_update(mc, args):
@utils.arg('--address', metavar='<ADDRESS>',
help='A valid EMAIL Address, URL, or SERVICE KEY.')
@utils.arg('--period', metavar='<PERIOD>', type=int,
help='A period for the notification method. Can only be non zero with webhooks')
help='A period for the notification method.')
def do_notification_patch(mc, args):
'''Patch notification.'''
fields = {}
@ -738,9 +727,6 @@ def do_notification_patch(mc, args):
if args.address:
fields['address'] = args.address
if args.period or args.period == 0:
if args.type and not _validate_notification_period(
args.period, args.type.upper()):
return
fields['period'] = args.period
try:
notification = mc.notifications.patch(**fields)

View File

@ -0,0 +1,4 @@
---
features:
- |
Adds support for setting notification period for all types.