From 293cf1cc355275534623721f8f0ba67dd75030ab Mon Sep 17 00:00:00 2001 From: pengyuesheng Date: Mon, 24 Jun 2019 09:56:48 +0800 Subject: [PATCH] Add the unit test for create and update action Change-Id: I05dc7bacaa155d7c1deae97e3c7e9786f7bc177d --- mistraldashboard/actions/tests.py | 32 +++++++++++++++++++ .../test/test_data/mistral_data.py | 1 + 2 files changed, 33 insertions(+) diff --git a/mistraldashboard/actions/tests.py b/mistraldashboard/actions/tests.py index 7bffefc..65164c3 100644 --- a/mistraldashboard/actions/tests.py +++ b/mistraldashboard/actions/tests.py @@ -35,6 +35,38 @@ class ActionsTest(test.TestCase): marker=None, sort_keys='name', sort_dirs='desc', paginate=True, reversed_order=True) + @horizon_test.create_mocks({api: ('action_create',)}) + def test_create_post(self): + action = self.mistralclient_actions.first() + self.mock_action_create.return_value = action + url = reverse("horizon:mistral:actions:create") + form_data = { + 'definition_source': 'raw', + 'definition_data': action.definition + } + res = self.client.post(url, form_data) + + self.assertNoFormErrors(res) + self.mock_action_create.assert_called_once_with( + horizon_test.IsHttpRequest(), + action.definition) + + @horizon_test.create_mocks({api: ('action_update',)}) + def test_update_post(self): + action = self.mistralclient_actions.first() + self.mock_action_update.return_value = action + url = reverse("horizon:mistral:actions:update") + form_data = { + 'definition_source': 'raw', + 'definition_data': action.definition + } + res = self.client.post(url, form_data) + + self.assertNoFormErrors(res) + self.mock_action_update.assert_called_once_with( + horizon_test.IsHttpRequest(), + action.definition) + @horizon_test.create_mocks({api: ('action_get',)}) def test_detail(self): action = self.mistralclient_actions.list()[0] diff --git a/mistraldashboard/test/test_data/mistral_data.py b/mistraldashboard/test/test_data/mistral_data.py index 35cb86f..d916fa7 100644 --- a/mistraldashboard/test/test_data/mistral_data.py +++ b/mistraldashboard/test/test_data/mistral_data.py @@ -69,6 +69,7 @@ def data(TEST): 'input': 'param1', 'description': 'my cool action', 'tags': ['test'], + 'definition': '1', 'created_at': '1', 'updated_at': '1' }