From f7501a8716e02d33d9740c67361e429b99e79711 Mon Sep 17 00:00:00 2001 From: Winson Chan Date: Fri, 11 Nov 2016 20:30:51 +0000 Subject: [PATCH] Use mock for a bad HTTP call in unit tests Depending on the test environment, in test_retry_policy and test_task_defaults_on_error unit tests, the bad URL in the workbook/workflow returned an unexpected response. These are poorly written unit tests as they try to make actual HTTP call to the bad URLs. This patch mocks the HTTP calls instead. Change-Id: Ib155bfe8040f05fe05f9665d3e75f98e205bdd6b Closes-Bug: bug/1641209 --- mistral/tests/unit/engine/test_policies.py | 6 ++++++ mistral/tests/unit/engine/test_task_defaults.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/mistral/tests/unit/engine/test_policies.py b/mistral/tests/unit/engine/test_policies.py index 225dd1356..b07110990 100644 --- a/mistral/tests/unit/engine/test_policies.py +++ b/mistral/tests/unit/engine/test_policies.py @@ -14,6 +14,7 @@ import mock from oslo_config import cfg +import requests from mistral.actions import std_actions from mistral.db.v2 import api as db_api @@ -512,6 +513,11 @@ class PoliciesTest(base.EngineTestCase): # Need to create a better test. # self.assertEqual(2, task_ex.in_context['wait_after']) + @mock.patch.object( + requests, + 'request', + mock.MagicMock(side_effect=Exception()) + ) def test_retry_policy(self): wb_service.create_workbook_v2(RETRY_WB) diff --git a/mistral/tests/unit/engine/test_task_defaults.py b/mistral/tests/unit/engine/test_task_defaults.py index 52bd14382..52fab3e04 100644 --- a/mistral/tests/unit/engine/test_task_defaults.py +++ b/mistral/tests/unit/engine/test_task_defaults.py @@ -13,7 +13,9 @@ # limitations under the License. import datetime as dt +import mock from oslo_config import cfg +import requests from mistral.db.v2 import api as db_api from mistral.services import scheduler @@ -28,6 +30,12 @@ cfg.CONF.set_default('auth_enable', False, group='pecan') class TaskDefaultsDirectWorkflowEngineTest(base.EngineTestCase): + + @mock.patch.object( + requests, + 'request', + mock.MagicMock(side_effect=Exception()) + ) def test_task_defaults_on_error(self): wf_text = """--- version: '2.0'