From 0651fff9105c6714aed35623f32ab7eb4c1cddc6 Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Fri, 16 May 2025 10:43:16 +0200 Subject: [PATCH] Added unit test to validate audit creation with no goal and no name This patch is adding a new unit test to validate the behavior of the API when trying to create an audit without a goal (whether using a goal or audit template parameters) and no name is provided. Related-Bug: https://bugs.launchpad.net/watcher/+bug/2110947 Change-Id: I04df10a8a0eea4509856f2f4b9d11bae24cd563a --- watcher/tests/api/v1/test_audits.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index c7506d044..37ab85dc3 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -987,6 +987,26 @@ class TestPost(api_base.FunctionalTest): self.assertEqual(HTTPStatus.CREATED, response.status_int) self.assertTrue(response.json['force']) + @mock.patch.object(deapi.DecisionEngineAPI, 'trigger_audit') + def test_create_audit_with_no_goal_no_name(self, mock_trigger_audit): + mock_trigger_audit.return_value = mock.ANY + + audit_dict = post_get_test_audit( + params_to_exclude=['uuid', 'state', 'interval', 'scope', + 'next_run_time', 'hostname', 'goal', + 'audit_template_uuid', 'name']) + + response = self.post_json( + '/audits', + audit_dict, + expect_errors=True, + headers={'OpenStack-API-Version': 'infra-optim 1.2'}) + self.assertEqual('application/json', response.content_type) + # (amoralej) this should return HTTP error 400 with a proper message. + # I am adding this test to show the bug here, I will switch it to the + # expected error in the fixing patch. + self.assertEqual(HTTPStatus.INTERNAL_SERVER_ERROR, response.status_int) + class TestDelete(api_base.FunctionalTest):