本文整理汇总了Python中helpers.FakeArgs.child方法的典型用法代码示例。如果您正苦于以下问题:Python FakeArgs.child方法的具体用法?Python FakeArgs.child怎么用?Python FakeArgs.child使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.FakeArgs
的用法示例。
在下文中一共展示了FakeArgs.child方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call_policy
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import child [as 别名]
def test_call_policy(self):
xproto = \
"""
policy sub_policy < ctx.user = obj.user >
policy output < *sub_policy(child) >
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
exec(output,globals()) # This loads the generated function, which should look like this:
"""
def policy_sub_policy_enforcer(obj, ctx):
i1 = (ctx.user == obj.user)
return i1
def policy_output_enforcer(obj, ctx):
i1 = policy_sub_policy_enforcer(obj.child, ctx)
return i1
"""
obj = FakeArgs()
obj.child = FakeArgs()
obj.child.user = 1
ctx = FakeArgs()
ctx.user = 1
verdict = policy_output_enforcer(obj, ctx)
self.assertTrue(verdict)
示例2: test_call_policy
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import child [as 别名]
def test_call_policy(self):
xproto = \
"""
policy sub_policy < ctx.user = obj.user >
policy output < *sub_policy(child) >
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
exec(output,globals()) # This loads the generated function, which should look like this:
"""
def policy_sub_policy_validator(obj, ctx):
i1 = (ctx.user == obj.user)
if (not i1):
raise ValidationError('Necessary Failure')
def policy_output_validator(obj, ctx):
i1 = policy_sub_policy_validator(obj.child, ctx)
if (not i1):
raise ValidationError('Necessary Failure')
"""
obj = FakeArgs()
obj.child = FakeArgs()
obj.child.user = 1
ctx = FakeArgs()
ctx.user = 1
with self.assertRaises(Exception):
verdict = policy_output_enforcer(obj, ctx)