Exemplo n.º 1
0
    def test_select(self):
        policy = DictPolicyNode()
        foo_node = DictPolicyNode()
        bar_node = LeafPolicyNode(Value(5))

        foo_node['bar'] = bar_node
        policy["foo"] = foo_node

        partial = Partial(policy)

        # select existing partial
        path = ["foo", "bar"]
        scope = "/{}".format("/".join(path))
        node, new_partial = partial.select(scope)
        self.assertEqual(partial.root, new_partial.root)
        self.assertEqual(LeafPolicyNode(Value(5)), node)
        self.assertEqual(path, new_partial.path)

        # select new partial
        path = ["foo", "baz"]
        scope = "/{}".format("/".join(path))
        value, new_partial = partial.select(scope)
        self.assertNotEqual(partial.root, new_partial.root)
        self.assertEqual(UnknownPolicyNode(), value)
        self.assertEqual(path, new_partial.path)

        # make sure /foo/bar still exists in new_partial
        path = ["foo", "bar"]
        scope = "/{}".format("/".join(path))
        value, new_new_partial = new_partial.select(scope)
        self.assertEqual(LeafPolicyNode(Value(5)), value)
Exemplo n.º 2
0
    def test_select(self):
        policy = DictPolicyNode()
        foo_node = DictPolicyNode()
        bar_node = LeafPolicyNode(Value(5))

        foo_node['bar'] = bar_node
        policy["foo"] = foo_node

        partial = Partial(Zipper([], policy))

        # select existing partial
        path = ["foo", "bar"]
        scope = "/{}".format("/".join(path))
        node, new_partial = partial.select(scope)
        self.assertEqual(partial.root, new_partial.root)
        self.assertEqual(LeafPolicyNode(Value(5)), node)
        self.assertEqual(path, new_partial.path)

        # select new partial
        path = ["foo", "baz"]
        scope = "/{}".format("/".join(path))
        value, new_partial = partial.select(scope)
        self.assertNotEqual(partial.root, new_partial.root)
        self.assertEqual(UnknownPolicyNode(), value)
        self.assertEqual(path, new_partial.path)

        # make sure /foo/bar still exists in new_partial
        path = ["foo", "bar"]
        scope = "/{}".format("/".join(path))
        value, new_new_partial = new_partial.select(scope)
        self.assertEqual(LeafPolicyNode(Value(5)), value)
Exemplo n.º 3
0
    def test_select_no_set_path(self):
        policy = DictPolicyNode()
        foo_node = DictPolicyNode()
        bar_node = LeafPolicyNode(Value(5))
        foo_node["bar"] = bar_node
        policy["foo"] = foo_node

        item = Partial(policy)

        path = "/foo/bar"
        value, new_item = item.select(path, set_path=False)
        self.assertEqual(LeafPolicyNode(Value(5)), value)
        self.assertEqual([], new_item.path)
Exemplo n.º 4
0
    def test_select_no_set_path(self):
        policy = DictPolicyNode()
        foo_node = DictPolicyNode()
        bar_node = LeafPolicyNode(Value(5))
        foo_node["bar"] = bar_node
        policy["foo"] = foo_node

        item = Partial(Zipper([], policy))

        path = "/foo/bar"
        value, new_item = item.select(path, set_path=False)
        self.assertEqual(LeafPolicyNode(Value(5)), value)
        self.assertEqual([], new_item.path)