def test_libvirtDocument(self): """Testing OvfLibvirt.libvirtDocument""" domain = self.testDocument.createElement('domain') domain.setAttribute('type', 'xen') elem = self.testDocument.createElement('name') elem.appendChild(self.testDocument.createTextNode('test')) domain.appendChild(elem) # no sections testDoc = OvfLibvirt.libvirtDocument(domain) testStr = self.docTag + '<domain type="xen"><name>test</name></domain>' self.assertEqual(Ovf.xmlString(testDoc), testStr) # new section clockSection = self.testDocument.createElement('clock') clockSection.setAttribute('sync','utc') testDoc = OvfLibvirt.libvirtDocument(domain, clockSection) testStr = self.docTag + '<domain type="xen"><name>test</name>' + \ '<clock sync="utc"/></domain>' self.assertEqual(Ovf.xmlString(testDoc), testStr) # replace section domain.appendChild(clockSection) newClockSection = self.testDocument.createElement('clock') newClockSection.setAttribute('sync','localtime') testDoc = OvfLibvirt.libvirtDocument(domain, newClockSection) testStr = self.docTag + '<domain type="xen"><name>test</name>' + \ '<clock sync="localtime"/></domain>' self.assertEqual(Ovf.xmlString(testDoc), testStr) # multiple sections (new and old) newNameSection = self.testDocument.createElement('name') nameNode = self.testDocument.createTextNode('test_completed') newNameSection.appendChild(nameNode) testDoc = OvfLibvirt.libvirtDocument(domain, newNameSection, newClockSection) testStr = self.docTag + '<domain type="xen">' + \ '<name>test_completed</name>' + \ '<clock sync="localtime"/></domain>' self.assertEqual(Ovf.xmlString(testDoc), testStr)