From 56a9dd0f08801fd2d6b8e7c6608fa988f55c94a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fran=C3=A7oise?= Date: Mon, 19 Sep 2016 10:50:04 +0200 Subject: [PATCH] Test code tidy up Removed some comments and replace some hardocded values with the correct variable. Change-Id: Ica897f2de25c9de04ec2d0f94e7a13e84ee97dbb --- watcher/tests/api/v1/test_actions_plans.py | 6 +++-- watcher/tests/api/v1/test_audits.py | 29 ---------------------- watcher/tests/objects/test_action.py | 6 ++--- watcher/tests/objects/test_action_plan.py | 6 ++--- 4 files changed, 10 insertions(+), 37 deletions(-) diff --git a/watcher/tests/api/v1/test_actions_plans.py b/watcher/tests/api/v1/test_actions_plans.py index 7c492bfcc..fb2668bf3 100644 --- a/watcher/tests/api/v1/test_actions_plans.py +++ b/watcher/tests/api/v1/test_actions_plans.py @@ -360,7 +360,7 @@ class TestPatch(api_base.FunctionalTest): test_time = datetime.datetime(2000, 1, 1, 0, 0) mock_utcnow.return_value = test_time - new_state = 'DELETED' + new_state = objects.action_plan.State.DELETED response = self.get_json( '/action_plans/%s' % self.action_plan.uuid) self.assertNotEqual(new_state, response['state']) @@ -591,7 +591,9 @@ class TestActionPlanPolicyEnforcement(api_base.FunctionalTest): self._common_policy_check( "action_plan:update", self.patch_json, '/action_plans/%s' % action_plan.uuid, - [{'path': '/state', 'value': 'DELETED', 'op': 'replace'}], + [{'path': '/state', + 'value': objects.action_plan.State.DELETED, + 'op': 'replace'}], expect_errors=True) def test_policy_disallow_delete(self): diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index 23b315e40..a04d6bfab 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -624,35 +624,6 @@ class TestPost(api_base.FunctionalTest): return audit_template -# class TestDelete(api_base.FunctionalTest): - -# def setUp(self): -# super(TestDelete, self).setUp() -# self.audit = obj_utils.create_test_audit(self.context) -# p = mock.patch.object(db_api.Connection, 'destroy_audit') -# self.mock_audit_delete = p.start() -# self.mock_audit_delete.side_effect = self._simulate_rpc_audit_delete -# self.addCleanup(p.stop) - -# def _simulate_rpc_audit_delete(self, audit_uuid): -# audit = objects.Audit.get_by_uuid(self.context, audit_uuid) -# audit.destroy() - -# def test_delete_audit(self): -# self.delete('/audits/%s' % self.audit.uuid) -# response = self.get_json('/audits/%s' % self.audit.uuid, -# expect_errors=True) -# self.assertEqual(404, response.status_int) -# self.assertEqual('application/json', response.content_type) -# self.assertTrue(response.json['error_message']) - -# def test_delete_audit_not_found(self): -# uuid = utils.generate_uuid() -# response = self.delete('/audits/%s' % uuid, expect_errors=True) -# self.assertEqual(404, response.status_int) -# self.assertEqual('application/json', response.content_type) -# self.assertTrue(response.json['error_message']) - class TestDelete(api_base.FunctionalTest): def setUp(self): diff --git a/watcher/tests/objects/test_action.py b/watcher/tests/objects/test_action.py index 7d386e08d..37ededf17 100644 --- a/watcher/tests/objects/test_action.py +++ b/watcher/tests/objects/test_action.py @@ -17,8 +17,8 @@ import mock from testtools import matchers from watcher.common import exception -# from watcher.common import utils as w_utils from watcher import objects +from watcher.objects import action as actionobject from watcher.tests.db import base from watcher.tests.db import utils @@ -93,12 +93,12 @@ class TestActionObject(base.DbTestCase): with mock.patch.object(self.dbapi, 'update_action', autospec=True) as mock_update_action: action = objects.Action.get_by_uuid(self.context, uuid) - action.state = 'SUCCEEDED' + action.state = actionobject.State.SUCCEEDED action.save() mock_get_action.assert_called_once_with(self.context, uuid) mock_update_action.assert_called_once_with( - uuid, {'state': 'SUCCEEDED'}) + uuid, {'state': actionobject.State.SUCCEEDED}) self.assertEqual(self.context, action._context) def test_refresh(self): diff --git a/watcher/tests/objects/test_action_plan.py b/watcher/tests/objects/test_action_plan.py index c7171e94b..764051116 100644 --- a/watcher/tests/objects/test_action_plan.py +++ b/watcher/tests/objects/test_action_plan.py @@ -17,8 +17,8 @@ import mock from testtools import matchers from watcher.common import exception -# from watcher.common import utils as w_utils from watcher import objects +from watcher.objects import action_plan as apobjects from watcher.tests.db import base from watcher.tests.db import utils @@ -147,13 +147,13 @@ class TestActionPlanObject(base.DbTestCase): autospec=True) as mock_update_action_plan: action_plan = objects.ActionPlan.get_by_uuid( self.context, uuid) - action_plan.state = 'SUCCEEDED' + action_plan.state = apobjects.State.SUCCEEDED action_plan.save() mock_get_action_plan.assert_called_once_with( self.context, uuid) mock_update_action_plan.assert_called_once_with( - uuid, {'state': 'SUCCEEDED'}) + uuid, {'state': apobjects.State.SUCCEEDED}) self.assertEqual(self.context, action_plan._context) def test_refresh(self):