Beispiel #1
0
    def test_invalid_dict(self):
        prefix_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix"><p:outer><p:a><p:storage>\
<p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a></p:outer>\
<p:storageVolumeId>88</p:storageVolumeId>\
<p:storageVolumeId>89</p:storageVolumeId></p:Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }]

        replaced_xml = util.replace_with_links(prefix_xml,
                                               dict_tag_props, {})
        print replaced_xml
        self.assertNotEqual(None, replaced_xml)
        self.assertEqual(util.replace_with_links(prefix_xml, [None],
                         {}), prefix_xml)
        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
            3.23: 32,
        }]

        util.replace_with_links(prefix_xml, dict_tag_props, {})
Beispiel #2
0
 def test_none_dict(self):
     xml_str = '<test>value</test>'
     self.assertEquals(xml_str, util.replace_with_links(xml_str, None, {}))
     self.assertEquals(xml_str,
                       util.replace_with_links(xml_str, [{
                           None: None
                       }], {}))
Beispiel #3
0
    def test_invalid_dict(self):
        prefix_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix"><p:outer><p:a><p:storage>\
<p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a></p:outer>\
<p:storageVolumeId>88</p:storageVolumeId>\
<p:storageVolumeId>89</p:storageVolumeId></p:Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }]

        replaced_xml = util.replace_with_links(prefix_xml, dict_tag_props, {})
        print replaced_xml
        self.assertNotEqual(None, replaced_xml)
        self.assertEqual(util.replace_with_links(prefix_xml, [None], {}),
                         prefix_xml)
        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
            3.23: 32,
        }]

        util.replace_with_links(prefix_xml, dict_tag_props, {})
Beispiel #4
0
    def test_tag_dictionary_error(self):
        xml_str = '<test xmlns="http://localhost/name"></test>'
        dict_tag_props = [{
            'tag': 'test',
            'tag_replacement': None,
            'tag_key': 'key',
            'tag_collection_url': 'http://localhost/v2.0/collection',
            'tag_attrib': None,
        }]

        try:
            util.replace_with_links(xml_str, dict_tag_props, {})
        except util.TagDictionaryError, err:
            print err
Beispiel #5
0
    def test_tag_dictionary_error(self):
        xml_str = '<test xmlns="http://localhost/name"></test>'
        dict_tag_props = [{
            'tag': 'test',
            'tag_replacement': None,
            'tag_key': 'key',
            'tag_collection_url': 'http://localhost/v2.0/collection',
            'tag_attrib': None,
        }]

        try:
            util.replace_with_links(xml_str, dict_tag_props, {})
        except util.TagDictionaryError, err:
            print err
Beispiel #6
0
    def test_replace_with_links(self):
        test_xml = \
            """<Vm><outer><a><storage><id>33</id><name>ESA</name>
                    </storage></a></outer>
                    <storageVolumeId>88</storageVolumeId>
                    <storageVolumeId>89</storageVolumeId>
                    <parent>
                        <id>89</id>
                        <name>testname</name>
                        <type>human</type>
                    </parent>
                    </Vm>"""

        expected_out_xml = '<Vm><outer><a><storage><id>33</id>\
<name>ESA</name></storage></a></outer>\
<storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="88">\
<atom:link href="http://localhost/v2.0/storage/88" rel="self"/>\
<atom:link href="http://localhost/storage/88" rel="bookmark"/>\
</storagevolume>\
<storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="89">\
<atom:link href="http://localhost/v2.0/storage/89" rel="self"/>\
<atom:link href="http://localhost/storage/89" rel="bookmark"/>\
</storagevolume>\
<person xmlns:atom="http://www.w3.org/2005/Atom" \
name="testname" type="human" id="89">\
<atom:link href="http://localhost/v2.0/people/89" rel="self"/>\
<atom:link href="http://localhost/people/89" rel="bookmark"/>\
</person></Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_replacement': 'storagevolume',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }, {
            'tag': 'vmHostId',
            'tag_replacement': 'vmhosts',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/vmhosts',
            'tag_attrib': None,
        }, {
            'tag': 'parent',
            'tag_replacement': 'person',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/people',
            'tag_attrib': ['name', 'type'],
        }]

#        element = util.replace_with_references(test_xml, dict_tag_props)

        out_dict = {}
        replaced_xml = util.replace_with_links(test_xml,
                                               dict_tag_props, out_dict)
        self.assertNotEqual(None, replaced_xml)
        self.compare_xml(expected_out_xml, replaced_xml)
Beispiel #7
0
    def test_replace_with_links(self):
        test_xml = \
            """<Vm><outer><a><storage><id>33</id><name>ESA</name>
                    </storage></a></outer>
                    <storageVolumeId>88</storageVolumeId>
                    <storageVolumeId>89</storageVolumeId>
                    <parent>
                        <id>89</id>
                        <name>testname</name>
                        <type>human</type>
                    </parent>
                    </Vm>"""

        expected_out_xml = \
            '<Vm><outer><a><storage><id>33</id><name>ESA</name></storage></a></outer>\
       <storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="88">\
       <atom:link href="http://localhost/v2.0/storage/88" rel="self"/><atom:link href="http://localhost/storage/88" rel="bookmark"/>\
       </storagevolume>\
       <storagevolume xmlns:atom="http://www.w3.org/2005/Atom" id="89">\
       <atom:link href="http://localhost/v2.0/storage/89" rel="self"/><atom:link href="http://localhost/storage/89" rel="bookmark"/>\
       </storagevolume>\
       <person xmlns:atom="http://www.w3.org/2005/Atom" name="testname" type="human" id="89">\
       <atom:link href="http://localhost/v2.0/people/89" rel="self"/><atom:link href="http://localhost/people/89" rel="bookmark"/>\
       </person></Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_replacement': 'storagevolume',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }, {
            'tag': 'vmHostId',
            'tag_replacement': 'vmhosts',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/vmhosts',
            'tag_attrib': None,
        }, {
            'tag': 'parent',
            'tag_replacement': 'person',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/people',
            'tag_attrib': ['name', 'type'],
        }]

        #        element = util.replace_with_references(test_xml, dict_tag_props)

        out_dict = {}
        replaced_xml = util.replace_with_links(test_xml, dict_tag_props,
                                               out_dict)
        self.assertNotEqual(None, replaced_xml)
        self.compare_xml(expected_out_xml, replaced_xml)
Beispiel #8
0
    def test_replace_with_links_prefix(self):
        prefix_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix"><p:outer><p:a><p:storage>\
        <p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a></p:outer>\
        <p:storageVolumeId>88</p:storageVolumeId>\
        <p:storageVolumeId>89</p:storageVolumeId></p:Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_replacement': 'storagevolume',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }, {
            'tag': 'vmHostId',
            'tag_replacement': 'vmhosts',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/vmhosts',
            'tag_attrib': None,
        }]

        expected_out_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix">\
        <p:outer>\
        <p:a><p:storage><p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a>\
        </p:outer>\
        <p:storagevolume xmlns:atom="http://www.w3.org/2005/Atom" p:id="88">\
        <atom:link href="http://localhost/v2.0/storage/88" rel="self"/>\
        <atom:link href="http://localhost/storage/88" rel="bookmark"/>\
        </p:storagevolume>\
        <p:storagevolume xmlns:atom="http://www.w3.org/2005/Atom" p:id="89">\
        <atom:link href="http://localhost/v2.0/storage/89" rel="self"/>\
        <atom:link href="http://localhost/storage/89" rel="bookmark"/>\
        </p:storagevolume>\
        </p:Vm>'

        out_dict = {}
        replaced_xml = util.replace_with_links(prefix_xml,
                                               dict_tag_props, out_dict)
        self.assertNotEqual(None, replaced_xml)
        self. compare_xml(expected_out_xml, replaced_xml)
Beispiel #9
0
    def test_replace_with_links_prefix(self):
        prefix_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix"><p:outer><p:a><p:storage>\
        <p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a></p:outer>\
        <p:storageVolumeId>88</p:storageVolumeId>\
        <p:storageVolumeId>89</p:storageVolumeId></p:Vm>'

        dict_tag_props = [{
            'tag': 'storageVolumeId',
            'tag_replacement': 'storagevolume',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/storage',
            'tag_attrib': None,
        }, {
            'tag': 'vmHostId',
            'tag_replacement': 'vmhosts',
            'tag_key': 'id',
            'tag_collection_url': 'http://localhost/v2.0/vmhosts',
            'tag_attrib': None,
        }]

        expected_out_xml = \
            '<p:Vm xmlns:p="http://localhost/prefix">\
        <p:outer>\
        <p:a><p:storage><p:id>33</p:id><p:name>ESA</p:name></p:storage></p:a>\
        </p:outer>\
        <p:storagevolume xmlns:atom="http://www.w3.org/2005/Atom" p:id="88">\
        <atom:link href="http://localhost/v2.0/storage/88" rel="self"/>\
        <atom:link href="http://localhost/storage/88" rel="bookmark"/>\
        </p:storagevolume>\
        <p:storagevolume xmlns:atom="http://www.w3.org/2005/Atom" p:id="89">\
        <atom:link href="http://localhost/v2.0/storage/89" rel="self"/>\
        <atom:link href="http://localhost/storage/89" rel="bookmark"/>\
        </p:storagevolume>\
        </p:Vm>'

        out_dict = {}
        replaced_xml = util.replace_with_links(prefix_xml, dict_tag_props,
                                               out_dict)
        self.assertNotEqual(None, replaced_xml)
        self.compare_xml(expected_out_xml, replaced_xml)
Beispiel #10
0
 def test_none_dict(self):
     xml_str = '<test>value</test>'
     self.assertEquals(xml_str, util.replace_with_links(xml_str,
                       None, {}))
     self.assertEquals(xml_str, util.replace_with_links(xml_str,
                       [{None: None}], {}))