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