|
67 | 67 | <type name=\"string\"/> \ |
68 | 68 | <default value=\"def\"/> \ |
69 | 69 | </leaf> \ |
| 70 | + <anydata name=\"any-data\"/> \ |
70 | 71 | </container> \ |
71 | 72 | <leaf name=\"y\"><type name=\"string\"/></leaf> \ |
72 | 73 | <anyxml name=\"any\"/> \ |
@@ -247,8 +248,6 @@ def test_ly_data_node(self): |
247 | 248 | # Tests |
248 | 249 | new_node = ly.Data_Node(root, root.schema().module(), "number32", "100") |
249 | 250 | self.assertIsNotNone(new_node) |
250 | | - dup_node = new_node.dup(0) |
251 | | - self.assertIsNotNone(dup_node) |
252 | 251 |
|
253 | 252 | except Exception as e: |
254 | 253 | self.fail(e) |
@@ -624,5 +623,131 @@ def test_ly_data_node_path(self): |
624 | 623 | except Exception as e: |
625 | 624 | self.fail(e) |
626 | 625 |
|
| 626 | + def test_ly_data_node_leaf(self): |
| 627 | + yang_folder = config.TESTS_DIR + "/api/files" |
| 628 | + config_file = config.TESTS_DIR + "/api/files/a.xml" |
| 629 | + |
| 630 | + try: |
| 631 | + ctx = ly.Context(yang_folder) |
| 632 | + self.assertIsNotNone(ctx) |
| 633 | + ctx.parse_module_mem(lys_module_a, ly.LYS_IN_YIN) |
| 634 | + root = ctx.parse_data_path(config_file, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 635 | + self.assertIsNotNone(root) |
| 636 | + |
| 637 | + new_node = ly.Data_Node(root, root.schema().module(), "number32", "100") |
| 638 | + self.assertIsNotNone(new_node) |
| 639 | + |
| 640 | + except Exception as e: |
| 641 | + self.fail(e) |
| 642 | + |
| 643 | + def test_ly_data_node_anydata(self): |
| 644 | + yang_folder = config.TESTS_DIR + "/api/files" |
| 645 | + config_file = config.TESTS_DIR + "/api/files/a.xml" |
| 646 | + |
| 647 | + try: |
| 648 | + ctx = ly.Context(yang_folder) |
| 649 | + self.assertIsNotNone(ctx) |
| 650 | + ctx.parse_module_mem(lys_module_a, ly.LYS_IN_YIN) |
| 651 | + root = ctx.parse_data_path(config_file, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 652 | + self.assertIsNotNone(root) |
| 653 | + mod = ctx.get_module("a", None, 1) |
| 654 | + |
| 655 | + new_node = ly.Data_Node(root, mod, "any-data", "100", ly.LYD_ANYDATA_CONSTSTRING) |
| 656 | + self.assertIsNotNone(new_node) |
| 657 | + |
| 658 | + except Exception as e: |
| 659 | + self.fail(e) |
| 660 | + |
| 661 | + def test_ly_data_node_dup(self): |
| 662 | + yang_folder = config.TESTS_DIR + "/api/files"; |
| 663 | + config_file = config.TESTS_DIR + "/api/files/a.xml"; |
| 664 | + |
| 665 | + try: |
| 666 | + ctx = ly.Context(yang_folder) |
| 667 | + self.assertIsNotNone(ctx) |
| 668 | + ctx.parse_module_mem(lys_module_a, ly.LYS_IN_YIN) |
| 669 | + root = ctx.parse_data_path(config_file, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 670 | + self.assertIsNotNone(root) |
| 671 | + |
| 672 | + new_node = ly.Data_Node(root, root.child().schema().module(), "bar-y") |
| 673 | + self.assertIsNotNone(new_node) |
| 674 | + dup_node = new_node.dup(0); |
| 675 | + self.assertIsNotNone(dup_node) |
| 676 | + |
| 677 | + except Exception as e: |
| 678 | + self.fail(e) |
| 679 | + |
| 680 | + |
| 681 | + def test_ly_data_node_dup_to_ctx(self): |
| 682 | + sch = "module x {\ |
| 683 | + namespace urn:x;\ |
| 684 | + prefix x;\ |
| 685 | + leaf x { type string; }}" |
| 686 | + data = "<x xmlns=\"urn:x\">hello</x>" |
| 687 | + |
| 688 | + try: |
| 689 | + ctx1 = ly.Context(None) |
| 690 | + self.assertIsNotNone(ctx1); |
| 691 | + ctx1.parse_module_mem(sch, ly.LYS_IN_YANG) |
| 692 | + data1 = ctx1.parse_data_mem(data, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 693 | + self.assertIsNotNone(data1) |
| 694 | + |
| 695 | + ctx2 = ly.Context(None) |
| 696 | + self.assertIsNotNone(ctx2) |
| 697 | + # we expect NULL due to missing schema in the second ctx |
| 698 | + dup_node = data1.dup_to_ctx(1, ctx2) |
| 699 | + self.assertIsNone(dup_node) |
| 700 | + |
| 701 | + ctx2.parse_module_mem(sch, ly.LYS_IN_YANG) |
| 702 | + # now we expect success due to schema being added to the second ctx |
| 703 | + dup_node = data1.dup_to_ctx(1, ctx2) |
| 704 | + self.assertIsNotNone(dup_node) |
| 705 | + |
| 706 | + except Exception as e: |
| 707 | + self.fail(e) |
| 708 | + |
| 709 | + def test_ly_data_node_validate_node(self): |
| 710 | + yang_folder = config.TESTS_DIR + "/api/files"; |
| 711 | + config_file = config.TESTS_DIR + "/api/files/a.xml"; |
| 712 | + |
| 713 | + try: |
| 714 | + ctx = ly.Context(yang_folder) |
| 715 | + self.assertIsNotNone(ctx) |
| 716 | + ctx.parse_module_mem(lys_module_a, ly.LYS_IN_YIN) |
| 717 | + root = ctx.parse_data_path(config_file, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 718 | + self.assertIsNotNone(root) |
| 719 | + |
| 720 | + rc = root.validate(ly.LYD_OPT_CONFIG, ctx) |
| 721 | + self.assertEqual(0, rc) |
| 722 | + new_node = ly.Data_Node(root, root.schema().module(), "number32", "1") |
| 723 | + self.assertIsNotNone(new_node) |
| 724 | + rc = root.validate(ly.LYD_OPT_CONFIG, new_node) |
| 725 | + self.assertEqual(0, rc) |
| 726 | + |
| 727 | + except Exception as e: |
| 728 | + self.fail(e) |
| 729 | + |
| 730 | + def test_ly_data_node_validate_value(self): |
| 731 | + yang_folder = config.TESTS_DIR + "/api/files"; |
| 732 | + config_file = config.TESTS_DIR + "/api/files/a.xml"; |
| 733 | + |
| 734 | + try: |
| 735 | + ctx = ly.Context(yang_folder) |
| 736 | + self.assertIsNotNone(ctx) |
| 737 | + ctx.parse_module_mem(lys_module_a, ly.LYS_IN_YIN) |
| 738 | + root = ctx.parse_data_path(config_file, ly.LYD_XML, ly.LYD_OPT_CONFIG | ly.LYD_OPT_STRICT) |
| 739 | + self.assertIsNotNone(root) |
| 740 | + |
| 741 | + rc = root.validate(ly.LYD_OPT_CONFIG, ctx) |
| 742 | + self.assertEqual(0, rc) |
| 743 | + new_node = ly.Data_Node(root, root.schema().module(), "number32", "1") |
| 744 | + self.assertIsNotNone(new_node) |
| 745 | + self.assertEqual(0, new_node.validate_value("1")) |
| 746 | + self.assertEqual(0, new_node.validate_value("100")) |
| 747 | + self.assertEqual(0, new_node.validate_value("110000000")) |
| 748 | + |
| 749 | + except Exception as e: |
| 750 | + self.fail(e) |
| 751 | + |
627 | 752 | if __name__ == '__main__': |
628 | 753 | unittest.main() |
0 commit comments