From 537389cad39453be7322480747522fe506933072 Mon Sep 17 00:00:00 2001 From: Craig Bryant Date: Mon, 13 Feb 2017 11:36:57 -0700 Subject: [PATCH] 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 --- monascaclient/tests/test_shell.py | 34 ++++++++++++++++++++++++------- monascaclient/v2_0/shell.py | 5 +++-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/monascaclient/tests/test_shell.py b/monascaclient/tests/test_shell.py index 5980847..610e565 100644 --- a/monascaclient/tests/test_shell.py +++ b/monascaclient/tests/test_shell.py @@ -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"); # 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()) 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.m.ReplayAll() @@ -279,15 +304,10 @@ class ShellTestMonascaCommands(ShellBase): headers=headers, json='id') - argstring = 'notification-patch {0} --type EMAIL --address' \ - ' john.doe@hpe.com --period 0'.format(id_str) + argstring = 'notification-patch {0} {1}'.format(id_str, args) retvalue = self.shell(argstring) self.assertRegexpMatches(retvalue, "id") - data = {'type': 'EMAIL', - 'address': 'john.doe@hpe.com', - 'period': 0} - self.assertHeaders() self.assertEqual(data, self.requests_mock.last_request.json()) diff --git a/monascaclient/v2_0/shell.py b/monascaclient/v2_0/shell.py index 411e9b1..aaf1373 100644 --- a/monascaclient/v2_0/shell.py +++ b/monascaclient/v2_0/shell.py @@ -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"); # 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: fields['name'] = args.name - fields['type'] = args.type + if args.type: + fields['type'] = args.type if args.address: fields['address'] = args.address if args.period or args.period == 0: