Fix notification-patch CLI fails if type not given
The type field was always being sent to the API even if a value wasn't given. Change code to only send type field if --type was actually used as an argument Added tests for this case Change-Id: Idb495eceb189db341753fd82be57d414e17cd64b Closes-Bug: #1664326
This commit is contained in:
parent
6c91e28edb
commit
537389cad3
@ -1,4 +1,4 @@
|
|||||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -266,6 +266,31 @@ class ShellTestMonascaCommands(ShellBase):
|
|||||||
self.assertEqual(data, self.requests_mock.last_request.json())
|
self.assertEqual(data, self.requests_mock.last_request.json())
|
||||||
|
|
||||||
def test_good_notifications_patch(self):
|
def test_good_notifications_patch(self):
|
||||||
|
args = '--type EMAIL --address john.doe@hpe.com --period 0'
|
||||||
|
data = {'type': 'EMAIL',
|
||||||
|
'address': 'john.doe@hpe.com',
|
||||||
|
'period': 0}
|
||||||
|
self.run_notification_patch_test(args, data)
|
||||||
|
|
||||||
|
def test_good_notifications_patch_just_name(self):
|
||||||
|
name = 'fred'
|
||||||
|
args = '--name ' + name
|
||||||
|
data = {'name': name}
|
||||||
|
self.run_notification_patch_test(args, data)
|
||||||
|
|
||||||
|
def test_good_notifications_patch_just_address(self):
|
||||||
|
address = 'fred@fl.com'
|
||||||
|
args = '--address ' + address
|
||||||
|
data = {'address': address}
|
||||||
|
self.run_notification_patch_test(args, data)
|
||||||
|
|
||||||
|
def test_good_notifications_patch_just_period(self):
|
||||||
|
period = 0
|
||||||
|
args = '--period ' + str(period)
|
||||||
|
data = {'period': period}
|
||||||
|
self.run_notification_patch_test(args, data)
|
||||||
|
|
||||||
|
def run_notification_patch_test(self, args, data):
|
||||||
self._script_keystone_client()
|
self._script_keystone_client()
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
|
|
||||||
@ -279,15 +304,10 @@ class ShellTestMonascaCommands(ShellBase):
|
|||||||
headers=headers,
|
headers=headers,
|
||||||
json='id')
|
json='id')
|
||||||
|
|
||||||
argstring = 'notification-patch {0} --type EMAIL --address' \
|
argstring = 'notification-patch {0} {1}'.format(id_str, args)
|
||||||
' john.doe@hpe.com --period 0'.format(id_str)
|
|
||||||
retvalue = self.shell(argstring)
|
retvalue = self.shell(argstring)
|
||||||
self.assertRegexpMatches(retvalue, "id")
|
self.assertRegexpMatches(retvalue, "id")
|
||||||
|
|
||||||
data = {'type': 'EMAIL',
|
|
||||||
'address': 'john.doe@hpe.com',
|
|
||||||
'period': 0}
|
|
||||||
|
|
||||||
self.assertHeaders()
|
self.assertHeaders()
|
||||||
self.assertEqual(data, self.requests_mock.last_request.json())
|
self.assertEqual(data, self.requests_mock.last_request.json())
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
|
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -758,7 +758,8 @@ def do_notification_patch(mc, args):
|
|||||||
if args.name:
|
if args.name:
|
||||||
fields['name'] = args.name
|
fields['name'] = args.name
|
||||||
|
|
||||||
fields['type'] = args.type
|
if args.type:
|
||||||
|
fields['type'] = args.type
|
||||||
if args.address:
|
if args.address:
|
||||||
fields['address'] = args.address
|
fields['address'] = args.address
|
||||||
if args.period or args.period == 0:
|
if args.period or args.period == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user