Take into account restriction's `strict` value

So far Nailgun always assumes that restrictions are strict, and doesn't
care about explicit (specified in restriction) `strict` value. This
commit fixes that, and if some restriction has an explicit `strict`
option it will be taken into account.

Change-Id: I5ef0e91f42cd708be5df56da461af4d7b568ae42
Closes-Bug: #1587773
This commit is contained in:
Igor Kalnitsky 2016-06-02 12:59:05 +03:00
parent 005c63c9e5
commit b349906a75
2 changed files with 29 additions and 1 deletions

View File

@ -455,3 +455,29 @@ class TestBasicAttributesValidator(base_test.BaseTestCase):
errors.InvalidData,
base.BasicAttributesValidator.validate_attributes,
yaml.load(attrs))
def test_restriction_strict(self):
context = {'context': {'existing': {'value': 13}}}
for strict in (False, True):
attrs = {
'section': {
'subsection': {
'restrictions': [{
'condition': 'context:nonexisting.value == 42',
'strict': strict,
}],
},
},
}
if strict:
assert_fn = self.assertRaises
else:
assert_fn = self.assertNotRaises
assert_fn(
TypeError,
base.BasicAttributesValidator.validate_attributes,
attrs,
models=context)

View File

@ -194,7 +194,9 @@ class RestrictionBase(object):
# Filter which restriction satisfied condition
satisfied = filter(
lambda item: Expression(
item.get('condition'), models, strict=strict).evaluate(),
item.get('condition'),
models,
strict=item.get('strict', strict)).evaluate(),
filterd_by_action_restrictions)
return {