Patch-notification failed with period=0
Patching from webhook notification to email notification fails when period is changed from 60 to 0 because when set period to be 0, the if statement "if args.period" returns false. Add unit tests for notification-patch and notification-update Change-Id: Id767514814e1f1ff72fb01da098dfef81c98f616
This commit is contained in:
parent
b1c695ec3e
commit
f745813366
@ -1,4 +1,4 @@
|
||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP
|
||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -279,6 +279,66 @@ class ShellTestMonascaCommands(ShellBase):
|
||||
retvalue = self.shell(argstr)
|
||||
self.assertRegexpMatches(retvalue, "id")
|
||||
|
||||
def test_good_notifications_patch(self):
|
||||
self._script_keystone_client()
|
||||
|
||||
id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
201,
|
||||
'Created',
|
||||
{'location': 'http://no.where/v2.0/notification-methods'},
|
||||
None)
|
||||
http.HTTPClient.json_request(
|
||||
'PATCH',
|
||||
'/notification-methods/' + id_str,
|
||||
data={'type': 'EMAIL',
|
||||
'address': 'john.doe@hpe.com',
|
||||
'period': 0},
|
||||
headers={'X-Auth-Key': 'password',
|
||||
'X-Auth-User': 'username'}).AndReturn((resp, 'id'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
argstring = 'notification-patch {0} --type EMAIL --address' \
|
||||
' john.doe@hpe.com --period 0'.format(id_str)
|
||||
retvalue = self.shell(argstring)
|
||||
self.assertRegexpMatches(retvalue, "id")
|
||||
|
||||
def test_bad_notifications_patch(self):
|
||||
self._script_keystone_client()
|
||||
|
||||
id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96490'
|
||||
argstring = 'notification-patch {0} --type EMAIL --address' \
|
||||
' john.doe@hpe.com --period 60'.format(id_str)
|
||||
self.m.ReplayAll()
|
||||
|
||||
retvalue = self.shell(argstring)
|
||||
self.assertRegexpMatches(retvalue, "^Invalid")
|
||||
|
||||
def test_good_notifications_update(self):
|
||||
self._script_keystone_client()
|
||||
|
||||
id_str = '0495340b-58fd-4e1c-932b-5e6f9cc96491'
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
201,
|
||||
'Created',
|
||||
{'location': 'http://no.where/v2.0/notification-methods'},
|
||||
None)
|
||||
http.HTTPClient.json_request(
|
||||
'PUT',
|
||||
'/notification-methods/' + id_str,
|
||||
data={'name': 'notification_updated_name',
|
||||
'type': 'EMAIL',
|
||||
'address': 'john.doe@hpe.com',
|
||||
'period': 0},
|
||||
headers={'X-Auth-Key': 'password',
|
||||
'X-Auth-User': 'username'}).AndReturn((resp, 'id'))
|
||||
self.m.ReplayAll()
|
||||
|
||||
argstring = 'notification-update {0} notification_updated_name ' \
|
||||
'EMAIL john.doe@hpe.com 0'.format(id_str)
|
||||
retvalue = self.shell(argstring)
|
||||
self.assertRegexpMatches(retvalue, "id")
|
||||
|
||||
def test_good_alarm_definition_update(self):
|
||||
self._script_keystone_client()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development Company LP
|
||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -693,7 +693,7 @@ def do_notification_patch(mc, args):
|
||||
fields['type'] = args.type
|
||||
if args.address:
|
||||
fields['address'] = args.address
|
||||
if args.period:
|
||||
if args.period or args.period == 0:
|
||||
if args.type and not _validate_notification_period(
|
||||
args.period, args.type.upper()):
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user