From 35c4e93a098966b2bb18ec9553d43ca78257ba99 Mon Sep 17 00:00:00 2001 From: Vincent Francoise Date: Fri, 22 Apr 2016 18:03:41 +0200 Subject: [PATCH] Fixed audit creation bug in CLI This changeset fixes the issue with the audit creation. Change-Id: Ic1fd34f1f1db0e45e205a2d19b5d3538efe89925 Closes-Bug: #1573686 --- watcherclient/tests/v1/test_audit_shell.py | 22 +++++++++++++++++++++- watcherclient/v1/audit_shell.py | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/watcherclient/tests/v1/test_audit_shell.py b/watcherclient/tests/v1/test_audit_shell.py index ba4fa81..9c6d070 100644 --- a/watcherclient/tests/v1/test_audit_shell.py +++ b/watcherclient/tests/v1/test_audit_shell.py @@ -123,10 +123,30 @@ class AuditShellTest(utils.BaseTestCase): def test_do_audit_create(self): client_mock = mock.MagicMock() args = mock.MagicMock() - a_shell.do_audit_create(client_mock, args) client_mock.audit.create.assert_called_once_with() + def test_do_audit_create_with_audit_template_uuid(self): + client_mock = mock.MagicMock() + args = mock.MagicMock() + args.audit_template_uuid = 'a5194d0e-1702-4663-9234-5ab2cf8dafea' + + a_shell.do_audit_create(client_mock, args) + client_mock.audit.create.assert_called_once_with( + audit_template_uuid='a5194d0e-1702-4663-9234-5ab2cf8dafea') + + def test_do_audit_create_with_audit_template_name(self): + client_mock = mock.MagicMock( + audit_template=mock.Mock( + get=mock.Mock(return_value=mock.Mock( + uuid='a5194d0e-1702-4663-9234-5ab2cf8dafea')))) + args = mock.MagicMock() + args.audit_template_uuid = 'Test AT name' + + a_shell.do_audit_create(client_mock, args) + client_mock.audit.create.assert_called_once_with( + audit_template_uuid='a5194d0e-1702-4663-9234-5ab2cf8dafea') + def test_do_audit_create_with_deadline(self): client_mock = mock.MagicMock() args = mock.MagicMock() diff --git a/watcherclient/v1/audit_shell.py b/watcherclient/v1/audit_shell.py index 331d405..d44cb94 100644 --- a/watcherclient/v1/audit_shell.py +++ b/watcherclient/v1/audit_shell.py @@ -118,7 +118,7 @@ def do_audit_create(cc, args): if fields.get('audit_template_uuid'): if not utils.is_uuid_like(fields['audit_template_uuid']): fields['audit_template_uuid'] = cc.audit_template.get( - fields['audit_template']) + fields['audit_template_uuid']).uuid audit = cc.audit.create(**fields) field_list.append('uuid') data = dict([(f, getattr(audit, f, '')) for f in field_list])