def test_subctx_policy(self): ctx = Context() subctx = ctx.subctx( lambda policy_rules: regarding('/foo', *policy_rules) ) subctx.append( set_value(5) ) result = run_policy(ctx.finalize()) self.assertEqual(result['foo'], 5)
def test_subctx_noop_policy(self): ctx = Context() foo_ctx_value = ctx.subctx( lambda policy_rules: regarding('/foo', *policy_rules) ) def with_foo(foo_value): return regarding('/bar', set_value(foo_value)) ctx.append(with_foo, foo_ctx_value) # foo is only used as a value - never being applied policy # rules itself. # ctx therefore should only have 1 policy, the `with_foo` # function above that just sets {foo: *, bar: foo} items, error_handler = ctx.get_finalized_items() self.assertEqual(len(items), 1) result = run_policy(ctx.finalize(), {"foo": "zebra"}) self.assertEqual(result['bar'], "zebra")