ironic-inspector/ironic_inspector/test/test_plugins_base.py
Dmitry Tantsur eb9b3da67a Add introspection rules support
This patch introduces a simple JSON-based DSL to run on introspected
data. Conditions and actions are provided via new plugin entry points.

This patch is missing PUT operation on a rule, this can be added later.

Also not all planned conditions and actions are added in this patch,
will also follow up.

Implements: blueprint rules
Change-Id: If4d17b5f1462d03879cb4c2ff4e5cb3ea364b697
2015-09-14 14:56:09 +02:00

45 lines
1.7 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ironic_inspector.plugins import base
from ironic_inspector.test import base as test_base
class WithValidation(base.WithValidation):
REQUIRED_PARAMS = {'x'}
OPTIONAL_PARAMS = {'y', 'z'}
class TestWithValidation(test_base.BaseTest):
def setUp(self):
super(TestWithValidation, self).setUp()
self.test = WithValidation()
def test_ok(self):
for x in (1, 0, '', False, True):
self.test.validate({'x': x})
self.test.validate({'x': 'x', 'y': 42})
self.test.validate({'x': 'x', 'y': 42, 'z': False})
def test_required_missing(self):
err_re = 'missing required parameter\(s\): x'
self.assertRaisesRegexp(ValueError, err_re, self.test.validate, {})
self.assertRaisesRegexp(ValueError, err_re, self.test.validate,
{'x': None})
self.assertRaisesRegexp(ValueError, err_re, self.test.validate,
{'y': 1, 'z': 2})
def test_unexpected(self):
self.assertRaisesRegexp(ValueError, 'unexpected parameter\(s\): foo',
self.test.validate, {'foo': 'bar', 'x': 42})