Author: gchapelle Date: Wed Nov 16 18:45:14 2005 New Revision: 1848 Modified: azax/trunk/azaxresponse.py azax/trunk/tests/test_azaxresponse.py Log: some tests pass
Modified: azax/trunk/azaxresponse.py ============================================================================== --- azax/trunk/azaxresponse.py (original) +++ azax/trunk/azaxresponse.py Wed Nov 16 18:45:14 2005 @@ -29,8 +29,8 @@ def __init__(self, commands_ob, name, selector): etree = config.etree self.ob = etree.SubElement(commands_ob, 'command') - self.ob.set('name', name) self.ob.set('selector', selector) + self.ob.set('name', name) def addData(self, name): etree = config.etree Modified: azax/trunk/tests/test_azaxresponse.py ============================================================================== --- azax/trunk/tests/test_azaxresponse.py (original) +++ azax/trunk/tests/test_azaxresponse.py Wed Nov 16 18:45:14 2005 @@ -42,62 +42,48 @@ def test_str_(self): ob = AzaxResponse() - self.assertEquals(self.cleanupXMLForTesting(str(ob)), '<selectors/>') + self.assertEquals(self.cleanupXMLForTesting(str(ob)), '<commands/>') - def test__createSelector(self): + def test_addCommand(self): ob = AzaxResponse() - selector = ob._createSelector('div.class') + command = ob.addCommand('name', 'selector') + self.assertEquals(self.cleanupXMLForTesting( + config.etree.tostring(command.ob)), + '<command selector="selector" name="name"/>') self.assertEquals(self.cleanupXMLForTesting(str(ob)), - '<selectors><selector><value>div.class</value><commands/></selector></selectors>') + '<commands><command selector="selector" name="name"/></commands>') - self.assertEquals(self.cleanupXMLForTesting(config.etree.tostring(selector.ob)), - '<selector><value>div.class</value><commands/></selector>') def test_setHtmlAsChildTextOnly(self): ob = AzaxResponse() ob.setHtmlAsChild('div.class', 'new_content') self.assertEquals(self.cleanupXMLForTesting(str(ob)), - '<selectors><selector><value>div.class</value><commands>' \ - '<command><name>setHtmlAsChild</name><data name="html">' \ - 'new_content</data></command></commands></selector>' \ - '</selectors>') - + '<commands><command selector="div.class" name="setHtmlAsChild">' \ + '<param name="html">new_content</param></command></commands>') + def test_setHtmlAsChildTagOnly(self): ob = AzaxResponse() ob.setHtmlAsChild('div.class', '<p>new_content</p>') self.assertEquals(self.cleanupXMLForTesting(str(ob)), - '<selectors><selector><value>div.class</value><commands>' \ - '<command><name>setHtmlAsChild</name><data name="html">' \ - '<p xmlns="http://www.w3.org/1999/xhtml">new_content</p>' \ - '</data></command></commands></selector>' \ - '</selectors>') + '<commands><command selector="div.class" name="setHtmlAsChild">' \ + '<param name="html"><p xmlns="http://www.w3.org/1999/xhtml">' \ + 'new_content</p></param></command></commands>') def test_setHtmlAsChildTagPlusText(self): ob = AzaxResponse() ob.setHtmlAsChild('div.class', '<p>new_content</p>after') self.assertEquals(self.cleanupXMLForTesting(str(ob)), - '<selectors><selector><value>div.class</value><commands>' \ - '<command><name>setHtmlAsChild</name><data name="html">' \ - '<p xmlns="http://www.w3.org/1999/xhtml">new_content</p>' \ - 'after</data></command></commands></selector>' \ - '</selectors>') + '<commands><command selector="div.class" name="setHtmlAsChild">' \ + '<param name="html"><p xmlns="http://www.w3.org/1999/xhtml">' \ + 'new_content</p>after</param></command></commands>') def test_setHtmlAsChildTextTagPlusText(self): ob = AzaxResponse() ob.setHtmlAsChild('div.class', 'before<p>new_content</p>after') self.assertEquals(self.cleanupXMLForTesting(str(ob)), - '<selectors><selector><value>div.class</value><commands>' \ - '<command><name>setHtmlAsChild</name><data name="html">' \ - 'before<p xmlns="http://www.w3.org/1999/xhtml">new_content</p>' \ - 'after</data></command></commands></selector>' \ - '</selectors>') - - def test__getSelector(self): - ob = AzaxResponse() - selector = ob._createSelector('div.class') - selector2 = ob._getSelector('div.class') - self.assertEquals(len(ob.selectors), 1) - self.assertEquals(selector2, selector) + '<commands><command selector="div.class" name="setHtmlAsChild">' \ + '<param name="html">before<p xmlns="http://www.w3.org/1999/xhtml">' \ + 'new_content</p>after</param></command></commands>') def test___call__(self): response = FakeResponse() @@ -107,40 +93,49 @@ self.assertEquals(response._stuff['Content-Type'], 'text/xml') class ElementTreeTestCase(AzaxResponseTestCase): - def __init__(self, methodName): + def afterSetUp(self): from elementtree import ElementTree as etree config.etree = etree - AzaxResponseTestCase.__init__(self, methodName) + + def test_etree(self): + self.assertEquals(config.etree.__name__, 'elementtree.ElementTree') class CElementTreeTestCase(AzaxResponseTestCase): - def __init__(self, methodName): + def afterSetUp(self): import cElementTree as etree config.etree = etree - AzaxResponseTestCase.__init__(self, methodName) + + def test_etree(self): + self.assertEquals(config.etree.__name__, 'cElementTree') class LxmlTestCase(AzaxResponseTestCase): - def __init__(self, methodName): + def afterSetUp(self): from lxml import etree config.etree = etree - AzaxResponseTestCase.__init__(self, methodName) + + def test_etree(self): + self.assertEquals(config.etree.__name__, 'lxml.etree') def test_suite(): suites = [] try: from lxml import etree - suites.append(unittest.makeSuite(LxmlTestCase)) except ImportError: pass + else: + suites.append(unittest.makeSuite(LxmlTestCase)) try: from elementtree import ElementTree as etree - suites.append(unittest.makeSuite(ElementTreeTestCase)) except ImportError: pass + else: + suites.append(unittest.makeSuite(ElementTreeTestCase)) try: import cElementTree as etree - suites.append(unittest.makeSuite(CElementTreeTestCase)) except ImportError: pass + else: + suites.append(unittest.makeSuite(CElementTreeTestCase)) suites.append(doctest.DocTestSuite('Products.azax.azaxresponse')) return unittest.TestSuite(suites) -- http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins