def test_gi_keyspec_string_method(self): #create a keyspec that points to a leaf node xpath = "D,/rw-base:colony[rw-base:name=\'abc\']/rw-fpath:bundle-ether[rw-fpath:name=\'xyz\']/rw-base:mtu" schema = RwFpathDYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertFalse(keyspec) xpath = "D,/rw-base:colony[rw-base:name=\'abc\']/rw-fpath:bundle-ether[rw-fpath:name=\'xyz\']/rw-fpath:mtu" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) v_create_string_no_schema = keyspec.create_string() print("create_string = %s" % (v_create_string,)) print("create_string_no_schema = %s" % (v_create_string_no_schema,)) self.assertEqual(v_create_string, xpath)
def test_gi_keyspec_string_method(self): #create a keyspec that points to a leaf node xpath = "D,/rw-base:colony[rw-base:name=\'abc\']/rw-fpath:bundle-ether[rw-fpath:name=\'xyz\']/rw-base:mtu" schema = RwFpathDYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertFalse(keyspec) xpath = "D,/rw-base:colony[rw-base:name=\'abc\']/rw-fpath:bundle-ether[rw-fpath:name=\'xyz\']/rw-fpath:mtu" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) v_create_string_no_schema = keyspec.create_string() print("create_string = %s" % (v_create_string,)) print("create_string_no_schema = %s" % (v_create_string_no_schema,)) self.assertEqual(v_create_string, xpath)
def test_gi_xpath_for_leaf(self): # some augment testcases for leaf yang nodes xpath = "D,/taugb1:b1_c/tauga1:a1_f1" schema = TestAugmentA1Yang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath) xpath = "D,/taugb1:b1_c/taugb1:b1_c1/taugb1:b1_f1" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath) xpath = "D,/taugb1:b1_c/taugb1:b1_c1/tauga1:a1_c1/tauga1:a1_f1" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath)
def test_keyspec_xpath(self): xpath = "/ps:person/ps:phone[ps:number=\'1234\']" schema = RwpersonDbYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) xpath_r = keyspec.to_xpath(schema) self.assertTrue(xpath_r) self.assertEqual(xpath_r, xpath) print(xpath_r)
def test_gi_xpath_for_leaf(self): # some augment testcases for leaf yang nodes xpath = "D,/taugb1:b1_c/tauga1:a1_f1" schema = TestAugmentA1Yang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath) xpath = "D,/taugb1:b1_c/taugb1:b1_c1/taugb1:b1_f1" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath) xpath = "D,/taugb1:b1_c/taugb1:b1_c1/tauga1:a1_c1/tauga1:a1_f1" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) v_create_string = keyspec.create_string(schema) self.assertEqual(v_create_string, xpath)
def test_keyspec_xpath(self): xpath = "/ps:person/ps:phone[ps:number=\'1234\']" schema = RwpersonDbYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) xpath_r = keyspec.to_xpath(schema) self.assertTrue(xpath_r) self.assertEqual(xpath_r, xpath) print(xpath_r)
def test_conversion_url_to_dts_xpath_2(self): self.maxDiff = None url = "/api/running/rwrestconf-configuration/" # trailing / on purpose expected = "" schema = load_multiple_schema_root(["rw-restconf"]) actual = create_dts_xpath_from_url(url, schema) value = RwKeyspec.path_from_xpath(RwRestconfYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
def test_conversion_url_to_dts_xpath_2(self): self.maxDiff = None url = "/api/running/rwrestconf-configuration/" # trailing / on purpose expected = "" schema = load_multiple_schema_root(["rw-restconf"]) actual = create_dts_xpath_from_url(url, schema) value = RwKeyspec.path_from_xpath(RwRestconfYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
def test_conversion_url_to_dts_xpath(self): self.maxDiff = None url = "/api/operational/car/toyota/models" expected = "" schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"]) actual = create_dts_xpath_from_url(url, schema) xpath = "D,/vehicle-a:car[vehicle-a:key_name = 'toyota']" value = RwKeyspec.path_from_xpath(VehicleAYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
def test_conversion_url_to_dts_xpath(self): self.maxDiff = None url = "/api/operational/car/toyota/models" expected = "" schema = load_multiple_schema_root(["vehicle-a", "vehicle-augment-a"]) actual = create_dts_xpath_from_url(url, schema) xpath = "D,/vehicle-a:car[vehicle-a:key_name = 'toyota']" value = RwKeyspec.path_from_xpath(VehicleAYang.get_schema(), actual, RwKeyspec.RwXpathType.KEYSPEC, None)
def test_gi_schema_context_methods(self): #create a keyspec that points to a leaf node xpath = "/rw-base:colony[rw-base:name=\'trafgen\']/rw-fpath:bundle-ether[rw-fpath:name=\'bundle1\']/rw-fpath:mtu" schema = RwFpathDYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) gi_desc = RwFpathDYang.ConfigColony_BundleEther.schema() self.assertTrue(gi_desc); lname = gi_desc.keyspec_leaf(keyspec) self.assertTrue(lname) print("Leaf " + lname) self.assertEqual(lname, "mtu") #Error case not a leaf keyspec xpath = "/rw-base:colony[rw-base:name=\'trafgen\']/rw-fpath:bundle-ether[rw-fpath:name=\'bundle1\']" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) lname = gi_desc.keyspec_leaf(keyspec) self.assertFalse(lname); #Error wrong schema gi_desc = RwFpathDYang.ConfigColony.schema() lname = gi_desc.keyspec_leaf(keyspec) self.assertFalse(lname)
def test_gi_schema_context_methods(self): #create a keyspec that points to a leaf node xpath = "/rw-base:colony[rw-base:name=\'trafgen\']/rw-fpath:bundle-ether[rw-fpath:name=\'bundle1\']/rw-fpath:mtu" schema = RwFpathDYang.get_schema() keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) gi_desc = RwFpathDYang.ConfigColony_BundleEther.schema() self.assertTrue(gi_desc); lname = gi_desc.keyspec_leaf(keyspec) self.assertTrue(lname) print("Leaf " + lname) self.assertEqual(lname, "mtu") #Error case not a leaf keyspec xpath = "/rw-base:colony[rw-base:name=\'trafgen\']/rw-fpath:bundle-ether[rw-fpath:name=\'bundle1\']" keyspec = RwKeyspec.path_from_xpath(schema, xpath, RwKeyspec.RwXpathType.KEYSPEC) self.assertTrue(keyspec) lname = gi_desc.keyspec_leaf(keyspec) self.assertFalse(lname); #Error wrong schema gi_desc = RwFpathDYang.ConfigColony.schema() lname = gi_desc.keyspec_leaf(keyspec) self.assertFalse(lname)