From 9ac3a7a4882bf8d0a0814d8cff9b4abd62a74a9f Mon Sep 17 00:00:00 2001 From: Liexiang Yue Date: Thu, 21 Mar 2019 11:40:49 +0800 Subject: Add unit_test for Multi-Cloud Fcaps enhancement Issue-ID: MULTICLOUD-495 Change-Id: I321823f894bba014f39455487687a0f77ff4234d Signed-off-by: Liexiang Yue --- fcaps/fcaps/vesagent/tests/tests_pm_vm.py | 90 +++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'fcaps') diff --git a/fcaps/fcaps/vesagent/tests/tests_pm_vm.py b/fcaps/fcaps/vesagent/tests/tests_pm_vm.py index 50db3c38..f40bd316 100644 --- a/fcaps/fcaps/vesagent/tests/tests_pm_vm.py +++ b/fcaps/fcaps/vesagent/tests/tests_pm_vm.py @@ -136,3 +136,93 @@ class PmVMTest(unittest.TestCase): def test_get_epoch_now_usecond(self): epoch = pm_vm.get_epoch_now_usecond() self.assertGreater(epoch, 1) + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_pm_vm(self, mock_call_req): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = pm_vm.buildBacklog_pm_vm( + vimid="fcaps-hudson-dc_RegionOne", + backlog_input=MOCK_BACKLOG_INPUT) + + self.assertIsNotNone(backlog) + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_pm_vm_wo_tenant_id(self, mock_call_req): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = pm_vm.buildBacklog_pm_vm( + vimid="fcaps-hudson-dc_RegionOne", + backlog_input=MOCK_BACKLOG_INPUT_wo_tenant_id) + self.assertIsNotNone(backlog) + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_pm_vm_wo_tenant(self, mock_call_req): + mock_call_req.side_effect = [ + (1, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body: failed"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = pm_vm.buildBacklog_pm_vm( + vimid="fcaps-hudson-dc_RegionOne", + backlog_input=MOCK_BACKLOG_INPUT_wo_tenant) + self.assertIsNone(backlog) + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_pm_vm_wo_server_id(self, mock_call_req): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = pm_vm.buildBacklog_pm_vm( + vimid="fcaps-hudson-dc_RegionOne", + backlog_input=MOCK_BACKLOG_INPUT_wo_server_id) + self.assertIsNotNone(backlog) + + @mock.patch.object(restcall, '_call_req') + def test_buildBacklog_pm_vm_wo_server(self, mock_call_req): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVERS_GET_RESPONSE), "MOCKED response body") + ] + backlog = pm_vm.buildBacklog_pm_vm( + vimid="fcaps-hudson-dc_RegionOne", + backlog_input=MOCK_BACKLOG_INPUT_wo_server) + self.assertIsNotNone(backlog) + + @mock.patch.object(vespublish, 'publishAnyEventToVES') + @mock.patch.object(restcall, '_call_req') + def test_processBacklog_pm_vm( + self, mock_call_req, mock_publishAnyEventToVES): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVER_GET_RESPONSE), "MOCKED response body") + ] + mock_publishAnyEventToVES.return_value = "mocked return value" + + result = pm_vm.processBacklog_pm_vm( + vesAgentConfig=MOCK_vesAgentConfig, + vesAgentState=MOCK_vesAgentState, + oneBacklog=MOCK_oneBacklog) + self.assertIsNone(result) + pass + + @mock.patch.object(vespublish, 'publishAnyEventToVES') + @mock.patch.object(restcall, '_call_req') + def test_processBacklog_pm_vm_wo_server( + self, mock_call_req, mock_publishAnyEventToVES): + mock_call_req.side_effect = [ + (0, json.dumps(MOCK_TOKEN_RESPONSE), "MOCKED response body"), + (0, json.dumps(MOCK_SERVER_GET_RESPONSE_empty), "MOCKED response body") + ] + mock_publishAnyEventToVES.return_value = "mocked return value" + + result = pm_vm.processBacklog_pm_vm( + vesAgentConfig=MOCK_vesAgentConfig, + vesAgentState=MOCK_vesAgentState, + oneBacklog=MOCK_oneBacklog) + + self.assertIsNone(result) -- cgit 1.2.3-korg