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