コード例 #1
0
    def test_conversion_XML_to_JSON_notification(self):
        yang_model = RwYang.Model.create_libncx()
        yang_model.load_module("vehicle-a")
        schema = yang_model.get_root_node()

        converter = XmlToJsonTranslator(schema, logger)

        expected_json = """
{"notification" : {"eventTime" : "2016-03-02T01:50:15.774039-05:00","vehicle-a:notif" : {"cont":{"cont-leaf" : "true","dict" : [{"value" : "bar","name" : "foo"},{"value" : "bar1","name" : "foo1"}]},"top-leaf" : 12}}}
"""
        notif_pb = VehicleAYang.YangNotif_VehicleA().create_notif()
        cont_pb = notif_pb.create_cont()
        dict_pb = cont_pb.create_dict()
        dict_pb.name = "foo"
        dict_pb.value = "bar"
        cont_pb.dict.append(dict_pb)
        dict_pb = cont_pb.create_dict()
        dict_pb.name = "foo1"
        dict_pb.value = "bar1"
        cont_pb.dict.append(dict_pb)
        cont_pb.cont_leaf = True
        notif_pb.cont = cont_pb
        notif_pb.top_leaf = 12

        content_xml = notif_pb.to_xml_v2(yang_model)
        notif_xml = """<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><eventTime>2016-03-02T01:50:15.774039-05:00</eventTime>"""
        notif_xml += content_xml
        notif_xml += "</notification>"

        json_str = converter.convert_notification(notif_xml)

        actual = _ordered(json.loads(json_str))
        expected = _ordered(json.loads(expected_json))
        self.assertEqual(actual, expected)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    def test_json_body_serialized_list_element(self):
        self.maxDiff = None
        url = "/api/config/misc/list-a/0"
        model = RwYang.model_create_libncx()
        model.load_schema_ypbc(VehicleAYang.get_schema())
        list_a_msg = VehicleAYang.YangData_VehicleA_Misc_ListA(id=0,
                                                               foo="asdf")
        list_a_json = list_a_msg.to_json(model)
        body = _collapse_string(list_a_json)

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><misc xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a></misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)
コード例 #5
0
ファイル: test_rest_put.py プロジェクト: gonotes/RIFT.ware
    def test_json_body_serialized_list_element(self):
        self.maxDiff = None
        url = "/api/config/misc/list-a/0"
        model = RwYang.model_create_libncx()
        model.load_schema_ypbc(VehicleAYang.get_schema())
        list_a_msg = VehicleAYang.YangData_VehicleA_Misc_ListA(id=0, foo="asdf")
        list_a_json = list_a_msg.to_json(model)
        body = _collapse_string(list_a_json)

        expected_xml = _collapse_string('''
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0"><misc xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a"><list-a xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a" xc:operation="replace"><id xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">0</id><foo xmlns="http://riftio.com/ns/core/mgmt/rwrestconf/test/vehicle-a">asdf</foo></list-a></misc></config>
        ''')

        schema = load_multiple_schema_root(["vehicle-a"])

        converter = ConfdRestTranslator(schema)

        actual_xml = converter.convert("PUT", url, (body, "json"))

        self.compare_doms(actual_xml, expected_xml)