Use Enum value instead of String Value
Fixing Gating Issue. Change-Id: I64a0df9e27e09172119a3a8f5395204b7476f23d
This commit is contained in:
parent
86f4f6a979
commit
aae3f79fef
@ -20,6 +20,7 @@ from wsme import types as wtypes
|
||||
from watcher.api.controllers.v1 import action as api_action
|
||||
from watcher.common import utils
|
||||
from watcher.db import api as db_api
|
||||
from watcher import objects
|
||||
from watcher.tests.api import base as api_base
|
||||
from watcher.tests.api import utils as api_utils
|
||||
from watcher.tests import base
|
||||
@ -444,8 +445,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
def test_patch_not_allowed(self, mock_utcnow):
|
||||
test_time = datetime.datetime(2000, 1, 1, 0, 0)
|
||||
mock_utcnow.return_value = test_time
|
||||
|
||||
new_state = 'SUBMITTED'
|
||||
new_state = objects.audit.State.SUBMITTED
|
||||
response = self.get_json('/actions/%s' % self.action.uuid)
|
||||
self.assertNotEqual(new_state, response['state'])
|
||||
|
||||
|
@ -693,8 +693,8 @@ class TestAuaditTemplatePolicyEnforcement(api_base.FunctionalTest):
|
||||
self._common_policy_check(
|
||||
"audit_template:update", self.patch_json,
|
||||
'/audit_templates/%s' % audit_template.uuid,
|
||||
[{'path': '/state', 'value': 'SUBMITTED', 'op': 'replace'}],
|
||||
expect_errors=True)
|
||||
[{'path': '/state', 'value': objects.audit.State.SUBMITTED,
|
||||
'op': 'replace'}], expect_errors=True)
|
||||
|
||||
def test_policy_disallow_create(self):
|
||||
fake_goal1 = obj_utils.get_test_goal(
|
||||
|
@ -265,7 +265,7 @@ class TestPatch(api_base.FunctionalTest):
|
||||
test_time = datetime.datetime(2000, 1, 1, 0, 0)
|
||||
mock_utcnow.return_value = test_time
|
||||
|
||||
new_state = 'SUBMITTED'
|
||||
new_state = objects.audit.State.SUBMITTED
|
||||
response = self.get_json('/audits/%s' % self.audit.uuid)
|
||||
self.assertNotEqual(new_state, response['state'])
|
||||
|
||||
@ -283,16 +283,16 @@ class TestPatch(api_base.FunctionalTest):
|
||||
self.assertEqual(test_time, return_updated_at)
|
||||
|
||||
def test_replace_non_existent_audit(self):
|
||||
response = self.patch_json('/audits/%s' % utils.generate_uuid(),
|
||||
[{'path': '/state', 'value': 'SUBMITTED',
|
||||
'op': 'replace'}],
|
||||
expect_errors=True)
|
||||
response = self.patch_json(
|
||||
'/audits/%s' % utils.generate_uuid(),
|
||||
[{'path': '/state', 'value': objects.audit.State.SUBMITTED,
|
||||
'op': 'replace'}], expect_errors=True)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
def test_add_ok(self):
|
||||
new_state = 'SUCCEEDED'
|
||||
new_state = objects.audit.State.SUCCEEDED
|
||||
response = self.patch_json(
|
||||
'/audits/%s' % self.audit.uuid,
|
||||
[{'path': '/state', 'value': new_state, 'op': 'add'}])
|
||||
@ -667,7 +667,7 @@ class TestDelete(api_base.FunctionalTest):
|
||||
|
||||
return_deleted_at = timeutils.strtime(audit['deleted_at'])
|
||||
self.assertEqual(timeutils.strtime(test_time), return_deleted_at)
|
||||
self.assertEqual('DELETED', audit['state'])
|
||||
self.assertEqual(objects.audit.State.DELETED, audit['state'])
|
||||
|
||||
def test_delete_audit_not_found(self):
|
||||
uuid = utils.generate_uuid()
|
||||
@ -714,8 +714,8 @@ class TestAuaditPolicyEnforcement(api_base.FunctionalTest):
|
||||
self._common_policy_check(
|
||||
"audit:update", self.patch_json,
|
||||
'/audits/%s' % audit.uuid,
|
||||
[{'path': '/state', 'value': 'SUBMITTED', 'op': 'replace'}],
|
||||
expect_errors=True)
|
||||
[{'path': '/state', 'value': objects.audit.State.SUBMITTED,
|
||||
'op': 'replace'}], expect_errors=True)
|
||||
|
||||
def test_policy_disallow_create(self):
|
||||
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
||||
|
@ -20,7 +20,7 @@ import six
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils as w_utils
|
||||
from watcher.objects import action as act_objects
|
||||
from watcher import objects
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.db import utils
|
||||
|
||||
@ -68,15 +68,15 @@ class TestDbActionFilters(base.DbTestCase):
|
||||
with freezegun.freeze_time(self.FAKE_TODAY):
|
||||
self.dbapi.update_action(
|
||||
self.action1.uuid,
|
||||
values={"state": act_objects.State.SUCCEEDED})
|
||||
values={"state": objects.action_plan.State.SUCCEEDED})
|
||||
with freezegun.freeze_time(self.FAKE_OLD_DATE):
|
||||
self.dbapi.update_action(
|
||||
self.action2.uuid,
|
||||
values={"state": act_objects.State.SUCCEEDED})
|
||||
values={"state": objects.action_plan.State.SUCCEEDED})
|
||||
with freezegun.freeze_time(self.FAKE_OLDER_DATE):
|
||||
self.dbapi.update_action(
|
||||
self.action3.uuid,
|
||||
values={"state": act_objects.State.SUCCEEDED})
|
||||
values={"state": objects.action_plan.State.SUCCEEDED})
|
||||
|
||||
def test_get_action_filter_deleted_true(self):
|
||||
with freezegun.freeze_time(self.FAKE_TODAY):
|
||||
@ -259,30 +259,31 @@ class DbActionTestCase(base.DbTestCase):
|
||||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit.id,
|
||||
first_action_id=None,
|
||||
state='RECOMMENDED')
|
||||
state=objects.action_plan.State.RECOMMENDED)
|
||||
action1 = self._create_test_action(
|
||||
id=1,
|
||||
action_plan_id=1,
|
||||
description='description action 1',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
next=None,
|
||||
state='PENDING')
|
||||
state=objects.action_plan.State.PENDING)
|
||||
action2 = self._create_test_action(
|
||||
id=2,
|
||||
action_plan_id=2,
|
||||
description='description action 2',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
next=action1['uuid'],
|
||||
state='PENDING')
|
||||
state=objects.action_plan.State.PENDING)
|
||||
action3 = self._create_test_action(
|
||||
id=3,
|
||||
action_plan_id=1,
|
||||
description='description action 3',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
next=action2['uuid'],
|
||||
state='ONGOING')
|
||||
res = self.dbapi.get_action_list(self.context,
|
||||
filters={'state': 'ONGOING'})
|
||||
state=objects.action_plan.State.ONGOING)
|
||||
res = self.dbapi.get_action_list(
|
||||
self.context,
|
||||
filters={'state': objects.action_plan.State.ONGOING})
|
||||
self.assertEqual([action3['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_action_list(self.context,
|
||||
@ -331,8 +332,9 @@ class DbActionTestCase(base.DbTestCase):
|
||||
|
||||
def test_update_action(self):
|
||||
action = self._create_test_action()
|
||||
res = self.dbapi.update_action(action['id'], {'state': 'CANCELLED'})
|
||||
self.assertEqual('CANCELLED', res.state)
|
||||
res = self.dbapi.update_action(
|
||||
action['id'], {'state': objects.action_plan.State.CANCELLED})
|
||||
self.assertEqual(objects.action_plan.State.CANCELLED, res.state)
|
||||
|
||||
def test_update_action_that_does_not_exist(self):
|
||||
self.assertRaises(exception.ActionNotFound,
|
||||
|
@ -255,28 +255,28 @@ class DbActionPlanTestCase(base.DbTestCase):
|
||||
audit_type='ONESHOT',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
deadline=None,
|
||||
state='ONGOING')
|
||||
state=ap_objects.State.ONGOING)
|
||||
action_plan1 = self._create_test_action_plan(
|
||||
id=1,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit['id'],
|
||||
first_action_id=None,
|
||||
state='RECOMMENDED')
|
||||
state=ap_objects.State.RECOMMENDED)
|
||||
action_plan2 = self._create_test_action_plan(
|
||||
id=2,
|
||||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit['id'],
|
||||
first_action_id=action_plan1['id'],
|
||||
state='ONGOING')
|
||||
state=ap_objects.State.ONGOING)
|
||||
|
||||
res = self.dbapi.get_action_plan_list(
|
||||
self.context,
|
||||
filters={'state': 'RECOMMENDED'})
|
||||
filters={'state': ap_objects.State.RECOMMENDED})
|
||||
self.assertEqual([action_plan1['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_action_plan_list(
|
||||
self.context,
|
||||
filters={'state': 'ONGOING'})
|
||||
filters={'state': ap_objects.State.ONGOING})
|
||||
self.assertEqual([action_plan2['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_action_plan_list(
|
||||
|
@ -270,13 +270,13 @@ class DbAuditTestCase(base.DbTestCase):
|
||||
audit_type='ONESHOT',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
deadline=None,
|
||||
state='ONGOING')
|
||||
state=audit_objects.State.ONGOING)
|
||||
audit2 = self._create_test_audit(
|
||||
id=2,
|
||||
audit_type='CONTINUOUS',
|
||||
uuid=w_utils.generate_uuid(),
|
||||
deadline=None,
|
||||
state='PENDING')
|
||||
state=audit_objects.State.PENDING)
|
||||
|
||||
res = self.dbapi.get_audit_list(self.context,
|
||||
filters={'audit_type': 'ONESHOT'})
|
||||
@ -288,12 +288,12 @@ class DbAuditTestCase(base.DbTestCase):
|
||||
|
||||
res = self.dbapi.get_audit_list(
|
||||
self.context,
|
||||
filters={'state': 'ONGOING'})
|
||||
filters={'state': audit_objects.State.ONGOING})
|
||||
self.assertEqual([audit1['id']], [r.id for r in res])
|
||||
|
||||
res = self.dbapi.get_audit_list(
|
||||
self.context,
|
||||
filters={'state': 'PENDING'})
|
||||
filters={'state': audit_objects.State.PENDING})
|
||||
self.assertEqual([audit2['id']], [r.id for r in res])
|
||||
|
||||
def test_get_audit_list_with_filter_by_uuid(self):
|
||||
|
@ -20,6 +20,7 @@ import six
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils as w_utils
|
||||
from watcher import objects
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.db import utils
|
||||
|
||||
@ -271,7 +272,7 @@ class DbEfficacyIndicatorTestCase(base.DbTestCase):
|
||||
uuid=w_utils.generate_uuid(),
|
||||
audit_id=audit.id,
|
||||
first_efficacy_indicator_id=None,
|
||||
state='RECOMMENDED')
|
||||
state=objects.action_plan.State.RECOMMENDED)
|
||||
efficacy_indicator1 = self._create_test_efficacy_indicator(
|
||||
id=1,
|
||||
name='indicator_1',
|
||||
@ -341,7 +342,8 @@ class DbEfficacyIndicatorTestCase(base.DbTestCase):
|
||||
def test_update_efficacy_indicator(self):
|
||||
efficacy_indicator = self._create_test_efficacy_indicator()
|
||||
res = self.dbapi.update_efficacy_indicator(
|
||||
efficacy_indicator.id, {'state': 'CANCELLED'})
|
||||
efficacy_indicator.id,
|
||||
{'state': objects.action_plan.State.CANCELLED})
|
||||
self.assertEqual('CANCELLED', res.state)
|
||||
|
||||
def test_update_efficacy_indicator_that_does_not_exist(self):
|
||||
|
@ -17,6 +17,7 @@
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from watcher.db import api as db_api
|
||||
from watcher import objects
|
||||
|
||||
|
||||
def get_test_audit_template(**kwargs):
|
||||
@ -97,7 +98,7 @@ def get_test_action(**kwargs):
|
||||
'key2': 'val2',
|
||||
'resource_id':
|
||||
'10a47dd1-4874-4298-91cf-eff046dbdb8d'}),
|
||||
'state': kwargs.get('state', 'PENDING'),
|
||||
'state': kwargs.get('state', objects.action_plan.State.PENDING),
|
||||
'next': kwargs.get('next', 2),
|
||||
'created_at': kwargs.get('created_at'),
|
||||
'updated_at': kwargs.get('updated_at'),
|
||||
@ -124,7 +125,7 @@ def get_test_action_plan(**kwargs):
|
||||
return {
|
||||
'id': kwargs.get('id', 1),
|
||||
'uuid': kwargs.get('uuid', '76be87bd-3422-43f9-93a0-e85a577e3061'),
|
||||
'state': kwargs.get('state', 'ONGOING'),
|
||||
'state': kwargs.get('state', objects.action_plan.State.ONGOING),
|
||||
'audit_id': kwargs.get('audit_id', 1),
|
||||
'strategy_id': kwargs.get('strategy_id', 1),
|
||||
'global_efficacy': kwargs.get('global_efficacy', {}),
|
||||
|
@ -133,7 +133,7 @@ class TestActionPlanObject(base.DbTestCase):
|
||||
m_soft_delete_efficacy_indicator.assert_called_once_with(
|
||||
efficacy_indicator['uuid'])
|
||||
m_update_action_plan.assert_called_once_with(
|
||||
uuid, {'state': 'DELETED'})
|
||||
uuid, {'state': apobjects.State.DELETED})
|
||||
self.assertEqual(self.context, action_plan._context)
|
||||
|
||||
def test_save(self):
|
||||
|
Loading…
Reference in New Issue
Block a user