Example #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)
Example #2
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)