def test_policy_delete(self, mock_find, mock_delete): x_obj = mock.Mock(id='POLICY_ID') mock_find.return_value = x_obj mock_delete.return_value = None req = orpo.PolicyDeleteRequest(identity='POLICY_ID') result = self.svc.policy_delete(self.ctx, req.obj_to_primitive()) self.assertIsNone(result) self.assertEqual('POLICY_ID', req.identity) mock_find.assert_called_once_with(self.ctx, 'POLICY_ID') mock_delete.assert_called_once_with(self.ctx, 'POLICY_ID')
def test_policy_delete_not_found(self, mock_find): mock_find.side_effect = exc.ResourceNotFound(type='policy', id='Bogus') req = orpo.PolicyDeleteRequest(identity='Bogus') ex = self.assertRaises(rpc.ExpectedException, self.svc.policy_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceNotFound, ex.exc_info[0]) self.assertEqual("The policy 'Bogus' could not be found.", str(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'Bogus')
def test_policy_delete_policy_in_use(self, mock_find, mock_delete): x_obj = mock.Mock(id='POLICY_ID') mock_find.return_value = x_obj err = exc.EResourceBusy(type='policy', id='POLICY_ID') mock_delete.side_effect = err req = orpo.PolicyDeleteRequest(identity='POLICY_ID') ex = self.assertRaises(rpc.ExpectedException, self.svc.policy_delete, self.ctx, req.obj_to_primitive()) self.assertEqual(exc.ResourceInUse, ex.exc_info[0]) self.assertEqual( _("The policy 'POLICY_ID' cannot be deleted: " "still attached to some clusters."), str(ex.exc_info[1])) mock_find.assert_called_once_with(self.ctx, 'POLICY_ID') mock_delete.assert_called_once_with(self.ctx, 'POLICY_ID')
def test_policy_delete(self): sot = policies.PolicyDeleteRequest(identity='foo') self.assertEqual('foo', sot.identity)