Test code tidy up

Removed some comments and replace some hardocded values with the
correct variable.

Change-Id: Ica897f2de25c9de04ec2d0f94e7a13e84ee97dbb
This commit is contained in:
Vincent Françoise
2016-09-19 10:50:04 +02:00
parent fc36a7a698
commit 56a9dd0f08
4 changed files with 10 additions and 37 deletions

View File

@@ -360,7 +360,7 @@ class TestPatch(api_base.FunctionalTest):
test_time = datetime.datetime(2000, 1, 1, 0, 0) test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time mock_utcnow.return_value = test_time
new_state = 'DELETED' new_state = objects.action_plan.State.DELETED
response = self.get_json( response = self.get_json(
'/action_plans/%s' % self.action_plan.uuid) '/action_plans/%s' % self.action_plan.uuid)
self.assertNotEqual(new_state, response['state']) self.assertNotEqual(new_state, response['state'])
@@ -591,7 +591,9 @@ class TestActionPlanPolicyEnforcement(api_base.FunctionalTest):
self._common_policy_check( self._common_policy_check(
"action_plan:update", self.patch_json, "action_plan:update", self.patch_json,
'/action_plans/%s' % action_plan.uuid, '/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) expect_errors=True)
def test_policy_disallow_delete(self): def test_policy_disallow_delete(self):

View File

@@ -624,35 +624,6 @@ class TestPost(api_base.FunctionalTest):
return audit_template 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): class TestDelete(api_base.FunctionalTest):
def setUp(self): def setUp(self):

View File

@@ -17,8 +17,8 @@ import mock
from testtools import matchers from testtools import matchers
from watcher.common import exception from watcher.common import exception
# from watcher.common import utils as w_utils
from watcher import objects from watcher import objects
from watcher.objects import action as actionobject
from watcher.tests.db import base from watcher.tests.db import base
from watcher.tests.db import utils from watcher.tests.db import utils
@@ -93,12 +93,12 @@ class TestActionObject(base.DbTestCase):
with mock.patch.object(self.dbapi, 'update_action', with mock.patch.object(self.dbapi, 'update_action',
autospec=True) as mock_update_action: autospec=True) as mock_update_action:
action = objects.Action.get_by_uuid(self.context, uuid) action = objects.Action.get_by_uuid(self.context, uuid)
action.state = 'SUCCEEDED' action.state = actionobject.State.SUCCEEDED
action.save() action.save()
mock_get_action.assert_called_once_with(self.context, uuid) mock_get_action.assert_called_once_with(self.context, uuid)
mock_update_action.assert_called_once_with( mock_update_action.assert_called_once_with(
uuid, {'state': 'SUCCEEDED'}) uuid, {'state': actionobject.State.SUCCEEDED})
self.assertEqual(self.context, action._context) self.assertEqual(self.context, action._context)
def test_refresh(self): def test_refresh(self):

View File

@@ -17,8 +17,8 @@ import mock
from testtools import matchers from testtools import matchers
from watcher.common import exception from watcher.common import exception
# from watcher.common import utils as w_utils
from watcher import objects from watcher import objects
from watcher.objects import action_plan as apobjects
from watcher.tests.db import base from watcher.tests.db import base
from watcher.tests.db import utils from watcher.tests.db import utils
@@ -147,13 +147,13 @@ class TestActionPlanObject(base.DbTestCase):
autospec=True) as mock_update_action_plan: autospec=True) as mock_update_action_plan:
action_plan = objects.ActionPlan.get_by_uuid( action_plan = objects.ActionPlan.get_by_uuid(
self.context, uuid) self.context, uuid)
action_plan.state = 'SUCCEEDED' action_plan.state = apobjects.State.SUCCEEDED
action_plan.save() action_plan.save()
mock_get_action_plan.assert_called_once_with( mock_get_action_plan.assert_called_once_with(
self.context, uuid) self.context, uuid)
mock_update_action_plan.assert_called_once_with( mock_update_action_plan.assert_called_once_with(
uuid, {'state': 'SUCCEEDED'}) uuid, {'state': apobjects.State.SUCCEEDED})
self.assertEqual(self.context, action_plan._context) self.assertEqual(self.context, action_plan._context)
def test_refresh(self): def test_refresh(self):