def test_dict_to_xml_raw_include(self):
        """test minimal dict with raw insert values"""
        xmlns = {
            '_': utils.NETCONF_NAMESPACE
        }

        xml_node = utils.generate_xml_node(
            {
                'a': {
                    '_!_': "<g><a n='1'></a><d n='2'></d><c n='3'></c></g>"
                }
            },
            xmlns,
            'rpc'
        )

        xml_node_string = etree.tostring(
            xml_node, pretty_print=False
        )

        self.assertEqual(
            xml_node_string,
            """<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:""" +
            """1.0"><a><g><a n="1"/><d n="2"/><c n="3"/></g></a></rpc>"""
        )
def _generate_goodbye(xmlns, netconf_namespace, message_id):
    """general final goodbye message"""
    goodbye_dict = {
        netconf_namespace + '@close-session': None,
        '_@@message-id': message_id
    }
    goodbye_xml = utils.generate_xml_node(goodbye_dict, xmlns,
                                          netconf_namespace + '@rpc')
    return etree.tostring(goodbye_xml,
                          pretty_print=True,
                          xml_declaration=True,
                          encoding='UTF-8')
    def test_dict_unsorted(self):
        """test simple dictionary that can be unsorted"""
        xmlns = {'_': utils.NETCONF_NAMESPACE, 'nm': 's'}

        xml_node = utils.generate_xml_node(self.UNSORTED_DICT, xmlns, 'rpc')

        xml_node_string = etree.tostring(xml_node, pretty_print=False)

        self.assertEqual(
            xml_node_string,
            """<rpc xmlns:nm="s" xmlns="urn:ietf:params:xml:ns:netconf:b""" +
            """ase:1.0"><a><b><c>d</c></b></a></rpc>""")
示例#4
0
    def test_dict_to_xml_turing(self):
        """test turing dict struct with tag list and attibutes"""
        xmlns = {
            self.FAKE_NS: 'a',
            self.REAL_NS: 'http://example.net/turing-machine',
            utils.DEFAULT_NCNS: utils.NETCONF_NAMESPACE
        }

        xml_node = utils.generate_xml_node(self.TURING_DICT, xmlns, 'rpc')

        xml_node_string = etree.tostring(xml_node, pretty_print=False)

        self.assertEqual(xml_node_string, self.TURING_STRIPPED)
示例#5
0
    def test_dict_to_xml(self):
        """test minimal dict struct with tag list and attibutes"""
        xmlns = {'_': utils.NETCONF_NAMESPACE, 'nm': 's'}

        xml_node = utils.generate_xml_node(self.SIMPLE_DICT, xmlns, 'rpc')

        xml_node_string = etree.tostring(xml_node, pretty_print=False)

        self.assertEqual(
            xml_node_string,
            """<rpc xmlns:nm="s" xmlns="urn:ietf:params:xml:ns:netc""" +
            """onf:base:1.0"><a xmlns:ns0="urn:ietf:params:xml:ns:n""" +
            """etconf:base:1.0"><c nm:nm="update"><d>1</d><d>2</d><""" +
            """d>3</d></c><b ns0:m="g">b</b></a></rpc>""")
    def test_dict_to_xml_turing(self):
        """test turing dict struct with tag list and attibutes"""
        xmlns = {
            self.FAKE_NS: 'a',
            self.REAL_NS: 'http://example.net/turing-machine',
            utils.DEFAULT_NCNS: utils.NETCONF_NAMESPACE
        }

        xml_node = utils.generate_xml_node(
            # we should use subelement because parent will be rpc
            self.TURING_DICT['rfc6020@rpc'],
            xmlns,
            # parent name
            'rpc')

        xml_node_string = etree.tostring(xml_node, pretty_print=False)

        self.assertEqual(xml_node_string, self.TURING_STRIPPED)
    def test_dict_to_xml_turing(self):
        """test turing dict struct with tag list and attibutes"""
        xmlns = {
            self.FAKE_NS: 'a',
            self.REAL_NS: 'http://example.net/turing-machine',
            utils.DEFAULT_NCNS: utils.NETCONF_NAMESPACE
        }

        xml_node = utils.generate_xml_node(
            self.TURING_DICT,
            xmlns,
            'rpc'
        )

        xml_node_string = etree.tostring(
            xml_node, pretty_print=False
        )

        self.assertEqual(xml_node_string, self.TURING_STRIPPED)
def _generate_hello(xmlns, netconf_namespace, capabilities):
    """generate initial hello message with capabilities"""
    if not capabilities:
        capabilities = []
    if netconf_connection.NETCONF_1_0_CAPABILITY not in capabilities:
        capabilities.append(netconf_connection.NETCONF_1_0_CAPABILITY)
    if netconf_connection.NETCONF_1_1_CAPABILITY not in capabilities:
        capabilities.append(netconf_connection.NETCONF_1_1_CAPABILITY)
    hello_dict = {
        netconf_namespace + '@capabilities': {
            netconf_namespace + '@capability': capabilities
        }
    }

    hello_xml = utils.generate_xml_node(hello_dict, xmlns,
                                        netconf_namespace + '@hello')
    return etree.tostring(hello_xml,
                          pretty_print=True,
                          xml_declaration=True,
                          encoding='UTF-8')
    def test_dict_to_xml(self):
        """test minimal dict struct with tag list and attibutes"""
        xmlns = {
            '_': utils.NETCONF_NAMESPACE,
            'nm': 's'
        }

        xml_node = utils.generate_xml_node(
            self.SIMPLE_DICT,
            xmlns,
            'rpc'
        )

        xml_node_string = etree.tostring(
            xml_node, pretty_print=False
        )

        self.assertEqual(
            xml_node_string,
            """<rpc xmlns:nm="s" xmlns="urn:ietf:params:xml:ns:netc""" +
            """onf:base:1.0"><a xmlns:ns0="urn:ietf:params:xml:ns:n""" +
            """etconf:base:1.0"><c nm:nm="update"><d>1</d><d>2</d><""" +
            """d>3</d></c><b ns0:m="g">b</b></a></rpc>"""
        )
示例#10
0
 def test_generate_xml_node(self):
     """can't generate enything without namspaces"""
     with self.assertRaises(cfy_exc.NonRecoverableError):
         utils.generate_xml_node({}, {}, "sometag")
 def test_generate_xml_node(self):
     """can't generate enything without namspaces"""
     with self.assertRaises(cfy_exc.NonRecoverableError):
         utils.generate_xml_node({}, {}, "sometag")