check audit state when deleting audit
If audit is 'ONGOING' or 'PENDING', don't delete audit. Change-Id: Iac714e7e78e7bb5b52f401e5b2ad0e1d8af8bb45 Closes-Bug: #1738358
This commit is contained in:
@@ -147,6 +147,11 @@ class TestListActionPlan(api_base.FunctionalTest):
|
||||
audit_id=audit2.id)
|
||||
action_plan_list.append(action_plan.uuid)
|
||||
|
||||
new_state = objects.audit.State.CANCELLED
|
||||
self.patch_json(
|
||||
'/audits/%s' % audit1.uuid,
|
||||
[{'path': '/state', 'value': new_state,
|
||||
'op': 'replace'}])
|
||||
self.delete('/audits/%s' % audit1.uuid)
|
||||
|
||||
response = self.get_json('/action_plans')
|
||||
|
||||
@@ -828,6 +828,23 @@ class TestDelete(api_base.FunctionalTest):
|
||||
def test_delete_audit(self, mock_utcnow):
|
||||
test_time = datetime.datetime(2000, 1, 1, 0, 0)
|
||||
mock_utcnow.return_value = test_time
|
||||
|
||||
new_state = objects.audit.State.ONGOING
|
||||
self.patch_json(
|
||||
'/audits/%s' % self.audit.uuid,
|
||||
[{'path': '/state', 'value': new_state,
|
||||
'op': 'replace'}])
|
||||
response = self.delete('/audits/%s' % self.audit.uuid,
|
||||
expect_errors=True)
|
||||
self.assertEqual(400, response.status_int)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
new_state = objects.audit.State.CANCELLED
|
||||
self.patch_json(
|
||||
'/audits/%s' % self.audit.uuid,
|
||||
[{'path': '/state', 'value': new_state,
|
||||
'op': 'replace'}])
|
||||
self.delete('/audits/%s' % self.audit.uuid)
|
||||
response = self.get_json('/audits/%s' % self.audit.uuid,
|
||||
expect_errors=True)
|
||||
|
||||
Reference in New Issue
Block a user