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:
parent
8a6a0dcb61
commit
9abbcd7e7f
@ -491,3 +491,29 @@ class TestBasicAttributesValidator(base_test.BaseTestCase):
|
|||||||
errors.InvalidData,
|
errors.InvalidData,
|
||||||
base.BasicAttributesValidator.validate_attributes,
|
base.BasicAttributesValidator.validate_attributes,
|
||||||
attrs)
|
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)
|
||||||
|
@ -194,7 +194,9 @@ class RestrictionBase(object):
|
|||||||
# Filter which restriction satisfied condition
|
# Filter which restriction satisfied condition
|
||||||
satisfied = filter(
|
satisfied = filter(
|
||||||
lambda item: Expression(
|
lambda item: Expression(
|
||||||
item.get('condition'), models, strict=strict).evaluate(),
|
item.get('condition'),
|
||||||
|
models,
|
||||||
|
strict=item.get('strict', strict)).evaluate(),
|
||||||
filterd_by_action_restrictions)
|
filterd_by_action_restrictions)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user