diff --git a/monascaclient/tests/v2_0/shell/test_notifications.py b/monascaclient/tests/v2_0/shell/test_notifications.py index 1c7015c..f5d0afa7 100644 --- a/monascaclient/tests/v2_0/shell/test_notifications.py +++ b/monascaclient/tests/v2_0/shell/test_notifications.py @@ -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): diff --git a/monascaclient/v2_0/shell.py b/monascaclient/v2_0/shell.py index 9537ec5..e54b460 100644 --- a/monascaclient/v2_0/shell.py +++ b/monascaclient/v2_0/shell.py @@ -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='', help='Name of the notification to create.') @utils.arg('type', metavar='', @@ -568,7 +561,7 @@ def _validate_notification_period(period, notification_type): @utils.arg('address', metavar='
', help='A valid EMAIL Address, URL, or SERVICE KEY.') @utils.arg('--period', metavar='', 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='
', help='A valid EMAIL Address, URL, or SERVICE KEY.') @utils.arg('period', metavar='', 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='
', help='A valid EMAIL Address, URL, or SERVICE KEY.') @utils.arg('--period', metavar='', 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) diff --git a/releasenotes/notes/relax-constraints-for-setting-periodic-notifications-502e6570b5481ea4.yaml b/releasenotes/notes/relax-constraints-for-setting-periodic-notifications-502e6570b5481ea4.yaml new file mode 100644 index 0000000..d7e3a64 --- /dev/null +++ b/releasenotes/notes/relax-constraints-for-setting-periodic-notifications-502e6570b5481ea4.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Adds support for setting notification period for all types.