import pytest
from twisted.words.xish import domish
@pytest.mark.usefixtures()
class TestDomish( object ):
def test_element( self ):
root = domish.Element( ( 'myxmlnamespace', 'root' ) ) # tuple parameter is the xmlns type and structure of the xml
assert "<root xmlns='myxmlnamespace'/>" == root.toXml()
def test_element_attribute( self ):
root = domish.Element( ( 'myxmlnamespace', 'root' ) )
root['myattribute'] = 'green'
assert "<root xmlns='myxmlnamespace' myattribute='green'/>" == root.toXml()
def test_element_add_empty_element( self ):
root = domish.Element( ( 'myxmlnamespace', 'root' ) )
root.addElement( 'child' )
assert "<root xmlns='myxmlnamespace'><child/></root>" == root.toXml()
def test_element_add_element_value( self ):
root = domish.Element( ( 'myxmlnamespace', 'root' ) )
root.addElement( 'child', content='value' )
assert "<root xmlns='myxmlnamespace'><child>value</child></root>" == root.toXml()
def test_html_example( self ):
html = domish.Element( ( "http://www.w3.org/1999/xhtml", 'html' ) )
head = domish.Element( ( None, 'head' ) )
head.addElement( 'title', content='my page' )
html.addChild( head )
html.addElement( 'body', content=' ' )
print html.toXml()
assert "<html xmlns='http://www.w3.org/1999/xhtml'><head><title>my page</title></head><body> </body></html>" == html.toXml()