Merge "Remove using of UUID field in POST methods of Watcher API"
This commit is contained in:
@@ -119,7 +119,7 @@ class Action(base.APIBase):
|
|||||||
self.action_next_uuid = None
|
self.action_next_uuid = None
|
||||||
# raise e
|
# raise e
|
||||||
|
|
||||||
uuid = types.uuid
|
uuid = wtypes.wsattr(types.uuid, readonly=True)
|
||||||
"""Unique UUID for this action"""
|
"""Unique UUID for this action"""
|
||||||
|
|
||||||
action_plan_uuid = wsme.wsproperty(types.uuid, _get_action_plan_uuid,
|
action_plan_uuid = wsme.wsproperty(types.uuid, _get_action_plan_uuid,
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class ActionPlan(base.APIBase):
|
|||||||
except exception.ActionNotFound:
|
except exception.ActionNotFound:
|
||||||
self._first_action_uuid = None
|
self._first_action_uuid = None
|
||||||
|
|
||||||
uuid = types.uuid
|
uuid = wtypes.wsattr(types.uuid, readonly=True)
|
||||||
"""Unique UUID for this action plan"""
|
"""Unique UUID for this action plan"""
|
||||||
|
|
||||||
first_action_uuid = wsme.wsproperty(
|
first_action_uuid = wsme.wsproperty(
|
||||||
|
|||||||
@@ -51,8 +51,6 @@ from watcher import objects
|
|||||||
|
|
||||||
class AuditPostType(wtypes.Base):
|
class AuditPostType(wtypes.Base):
|
||||||
|
|
||||||
uuid = wtypes.wsattr(types.uuid, mandatory=False)
|
|
||||||
|
|
||||||
audit_template_uuid = wtypes.wsattr(types.uuid, mandatory=True)
|
audit_template_uuid = wtypes.wsattr(types.uuid, mandatory=True)
|
||||||
|
|
||||||
type = wtypes.wsattr(wtypes.text, mandatory=True)
|
type = wtypes.wsattr(wtypes.text, mandatory=True)
|
||||||
@@ -68,7 +66,6 @@ class AuditPostType(wtypes.Base):
|
|||||||
raise exception.AuditTypeNotFound(audit_type=self.type)
|
raise exception.AuditTypeNotFound(audit_type=self.type)
|
||||||
|
|
||||||
return Audit(
|
return Audit(
|
||||||
uuid=self.uuid or utils.generate_uuid(),
|
|
||||||
audit_template_id=self.audit_template_uuid,
|
audit_template_id=self.audit_template_uuid,
|
||||||
type=self.type,
|
type=self.type,
|
||||||
deadline=self.deadline)
|
deadline=self.deadline)
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ class AuditTemplate(base.APIBase):
|
|||||||
between the internal object model and the API representation of an
|
between the internal object model and the API representation of an
|
||||||
audit template.
|
audit template.
|
||||||
"""
|
"""
|
||||||
uuid = types.uuid
|
|
||||||
|
uuid = wtypes.wsattr(types.uuid, readonly=True)
|
||||||
"""Unique UUID for this audit template"""
|
"""Unique UUID for this audit template"""
|
||||||
|
|
||||||
name = wtypes.text
|
name = wtypes.text
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
audit_template_dict = api_utils.audit_template_post_data()
|
audit_template_dict = api_utils.audit_template_post_data()
|
||||||
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
|
||||||
|
del audit_template_dict['uuid']
|
||||||
|
|
||||||
response = self.post_json('/audit_templates', audit_template_dict)
|
response = self.post_json('/audit_templates', audit_template_dict)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
@@ -399,10 +400,9 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
# Check location header
|
# Check location header
|
||||||
self.assertIsNotNone(response.location)
|
self.assertIsNotNone(response.location)
|
||||||
expected_location = \
|
expected_location = \
|
||||||
'/v1/audit_templates/%s' % audit_template_dict['uuid']
|
'/v1/audit_templates/%s' % response.json['uuid']
|
||||||
self.assertEqual(urlparse.urlparse(response.location).path,
|
self.assertEqual(urlparse.urlparse(response.location).path,
|
||||||
expected_location)
|
expected_location)
|
||||||
self.assertEqual(audit_template_dict['uuid'], response.json['uuid'])
|
|
||||||
self.assertNotIn('updated_at', response.json.keys)
|
self.assertNotIn('updated_at', response.json.keys)
|
||||||
self.assertNotIn('deleted_at', response.json.keys)
|
self.assertNotIn('deleted_at', response.json.keys)
|
||||||
return_created_at = timeutils.parse_isotime(
|
return_created_at = timeutils.parse_isotime(
|
||||||
@@ -417,6 +417,7 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
) as cn_mock:
|
) as cn_mock:
|
||||||
audit_template_dict = api_utils.audit_template_post_data(
|
audit_template_dict = api_utils.audit_template_post_data(
|
||||||
goal='DUMMY')
|
goal='DUMMY')
|
||||||
|
del audit_template_dict['uuid']
|
||||||
response = self.post_json('/audit_templates', audit_template_dict)
|
response = self.post_json('/audit_templates', audit_template_dict)
|
||||||
self.assertEqual(audit_template_dict['goal'],
|
self.assertEqual(audit_template_dict['goal'],
|
||||||
response.json['goal'])
|
response.json['goal'])
|
||||||
@@ -447,6 +448,20 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
self.assertEqual(400, response.status_int)
|
self.assertEqual(400, response.status_int)
|
||||||
assert not cn_mock.called
|
assert not cn_mock.called
|
||||||
|
|
||||||
|
def test_create_audit_template_with_uuid(self):
|
||||||
|
with mock.patch.object(
|
||||||
|
self.dbapi,
|
||||||
|
'create_audit_template',
|
||||||
|
wraps=self.dbapi.create_audit_template
|
||||||
|
) as cn_mock:
|
||||||
|
audit_template_dict = api_utils.audit_template_post_data()
|
||||||
|
|
||||||
|
response = self.post_json('/audit_templates', audit_template_dict,
|
||||||
|
expect_errors=True)
|
||||||
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
self.assertEqual(400, response.status_int)
|
||||||
|
assert not cn_mock.called
|
||||||
|
|
||||||
|
|
||||||
class TestDelete(api_base.FunctionalTest):
|
class TestDelete(api_base.FunctionalTest):
|
||||||
|
|
||||||
|
|||||||
@@ -433,6 +433,7 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
mock_utcnow.return_value = test_time
|
mock_utcnow.return_value = test_time
|
||||||
|
|
||||||
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
||||||
|
del audit_dict['uuid']
|
||||||
del audit_dict['state']
|
del audit_dict['state']
|
||||||
|
|
||||||
response = self.post_json('/audits', audit_dict)
|
response = self.post_json('/audits', audit_dict)
|
||||||
@@ -440,10 +441,9 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
self.assertEqual(201, response.status_int)
|
self.assertEqual(201, response.status_int)
|
||||||
# Check location header
|
# Check location header
|
||||||
self.assertIsNotNone(response.location)
|
self.assertIsNotNone(response.location)
|
||||||
expected_location = '/v1/audits/%s' % audit_dict['uuid']
|
expected_location = '/v1/audits/%s' % response.json['uuid']
|
||||||
self.assertEqual(urlparse.urlparse(response.location).path,
|
self.assertEqual(urlparse.urlparse(response.location).path,
|
||||||
expected_location)
|
expected_location)
|
||||||
self.assertEqual(audit_dict['uuid'], response.json['uuid'])
|
|
||||||
self.assertEqual(objects.audit.State.PENDING,
|
self.assertEqual(objects.audit.State.PENDING,
|
||||||
response.json['state'])
|
response.json['state'])
|
||||||
self.assertNotIn('updated_at', response.json.keys)
|
self.assertNotIn('updated_at', response.json.keys)
|
||||||
@@ -473,6 +473,7 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
mock_utcnow.return_value = test_time
|
mock_utcnow.return_value = test_time
|
||||||
|
|
||||||
audit_dict = post_get_test_audit()
|
audit_dict = post_get_test_audit()
|
||||||
|
del audit_dict['uuid']
|
||||||
del audit_dict['state']
|
del audit_dict['state']
|
||||||
# Make the audit template UUID some garbage value
|
# Make the audit template UUID some garbage value
|
||||||
audit_dict['audit_template_uuid'] = (
|
audit_dict['audit_template_uuid'] = (
|
||||||
@@ -492,6 +493,7 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
|
|
||||||
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
||||||
state = audit_dict['state']
|
state = audit_dict['state']
|
||||||
|
del audit_dict['uuid']
|
||||||
del audit_dict['state']
|
del audit_dict['state']
|
||||||
with mock.patch.object(self.dbapi, 'create_audit',
|
with mock.patch.object(self.dbapi, 'create_audit',
|
||||||
wraps=self.dbapi.create_audit) as cn_mock:
|
wraps=self.dbapi.create_audit) as cn_mock:
|
||||||
@@ -520,9 +522,20 @@ class TestPost(api_base.FunctionalTest):
|
|||||||
with mock.patch.object(deapi.DecisionEngineAPI,
|
with mock.patch.object(deapi.DecisionEngineAPI,
|
||||||
'trigger_audit') as de_mock:
|
'trigger_audit') as de_mock:
|
||||||
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
||||||
|
del audit_dict['uuid']
|
||||||
del audit_dict['state']
|
del audit_dict['state']
|
||||||
self.post_json('/audits', audit_dict)
|
response = self.post_json('/audits', audit_dict)
|
||||||
de_mock.assert_called_once_with(mock.ANY, audit_dict['uuid'])
|
de_mock.assert_called_once_with(mock.ANY, response.json['uuid'])
|
||||||
|
|
||||||
|
@mock.patch.object(deapi.DecisionEngineAPI, 'trigger_audit')
|
||||||
|
def test_create_audit_with_uuid(self, mock_trigger_audit):
|
||||||
|
mock_trigger_audit.return_value = mock.ANY
|
||||||
|
|
||||||
|
audit_dict = post_get_test_audit(state=objects.audit.State.PENDING)
|
||||||
|
response = self.post_json('/audits', audit_dict, expect_errors=True)
|
||||||
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
self.assertEqual(400, response.status_int)
|
||||||
|
assert not mock_trigger_audit.called
|
||||||
|
|
||||||
|
|
||||||
# class TestDelete(api_base.FunctionalTest):
|
# class TestDelete(api_base.FunctionalTest):
|
||||||
|
|||||||
@@ -371,13 +371,13 @@ class DbAuditTestCase(base.DbTestCase):
|
|||||||
self.context, audit['id'])
|
self.context, audit['id'])
|
||||||
|
|
||||||
def test_destroy_audit_by_uuid(self):
|
def test_destroy_audit_by_uuid(self):
|
||||||
uuid = w_utils.generate_uuid()
|
audit = self._create_test_audit()
|
||||||
self._create_test_audit(uuid=uuid)
|
|
||||||
self.assertIsNotNone(self.dbapi.get_audit_by_uuid(self.context,
|
self.assertIsNotNone(self.dbapi.get_audit_by_uuid(self.context,
|
||||||
uuid))
|
audit['uuid']))
|
||||||
self.dbapi.destroy_audit(uuid)
|
self.dbapi.destroy_audit(audit['uuid'])
|
||||||
self.assertRaises(exception.AuditNotFound,
|
self.assertRaises(exception.AuditNotFound,
|
||||||
self.dbapi.get_audit_by_uuid, self.context, uuid)
|
self.dbapi.get_audit_by_uuid, self.context,
|
||||||
|
audit['uuid'])
|
||||||
|
|
||||||
def test_destroy_audit_that_does_not_exist(self):
|
def test_destroy_audit_that_does_not_exist(self):
|
||||||
self.assertRaises(exception.AuditNotFound,
|
self.assertRaises(exception.AuditNotFound,
|
||||||
@@ -389,10 +389,3 @@ class DbAuditTestCase(base.DbTestCase):
|
|||||||
self.assertEqual(audit['id'], action_plan.audit_id)
|
self.assertEqual(audit['id'], action_plan.audit_id)
|
||||||
self.assertRaises(exception.AuditReferenced,
|
self.assertRaises(exception.AuditReferenced,
|
||||||
self.dbapi.destroy_audit, audit['id'])
|
self.dbapi.destroy_audit, audit['id'])
|
||||||
|
|
||||||
def test_create_audit_already_exists(self):
|
|
||||||
uuid = w_utils.generate_uuid()
|
|
||||||
self._create_test_audit(id=1, uuid=uuid)
|
|
||||||
self.assertRaises(exception.AuditAlreadyExists,
|
|
||||||
self._create_test_audit,
|
|
||||||
id=2, uuid=uuid)
|
|
||||||
|
|||||||
@@ -358,15 +358,3 @@ class DbAuditTemplateTestCase(base.DbTestCase):
|
|||||||
utils.create_test_audit_template,
|
utils.create_test_audit_template,
|
||||||
uuid=w_utils.generate_uuid(),
|
uuid=w_utils.generate_uuid(),
|
||||||
name='audit_template_name')
|
name='audit_template_name')
|
||||||
|
|
||||||
def test_audit_template_create_same_uuid(self):
|
|
||||||
uuid = w_utils.generate_uuid()
|
|
||||||
audit_template1 = utils.create_test_audit_template(
|
|
||||||
uuid=uuid,
|
|
||||||
name='audit_template_name_1')
|
|
||||||
self.assertEqual(audit_template1['uuid'], audit_template1.uuid)
|
|
||||||
self.assertRaises(
|
|
||||||
exception.AuditTemplateAlreadyExists,
|
|
||||||
utils.create_test_audit_template,
|
|
||||||
uuid=uuid,
|
|
||||||
name='audit_template_name_2')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user