Author: gchapelle
Date: Wed Nov 16 12:04:28 2005
New Revision: 1833

Modified:
   azax/trunk/azaxresponse.py
   azax/trunk/tests/test_azaxresponse.py
Log:
fix setHtmlAsData such that text only works

add tests


Modified: azax/trunk/azaxresponse.py
==============================================================================
--- azax/trunk/azaxresponse.py  (original)
+++ azax/trunk/azaxresponse.py  Wed Nov 16 12:04:28 2005
@@ -100,8 +100,9 @@
         self.wrapInHtmlNamespace(new_value, data)        
 
     def wrapInHtmlNamespace(self, new_value, data):
-        new_value = '<junk>' + new_value + '</junk>'
-        valuetree = etree.fromstring(new_value.encode('latin1'))
+        new_value = '<root>%s</root>' % new_value
+        valuetree = etree.fromstring(new_value)
+        data.text = valuetree.text
         for elem in valuetree.getchildren():
             elem.set('xmlns', 'http://www.w3.org/1999/xhtml')
             data.append(elem)

Modified: azax/trunk/tests/test_azaxresponse.py
==============================================================================
--- azax/trunk/tests/test_azaxresponse.py       (original)
+++ azax/trunk/tests/test_azaxresponse.py       Wed Nov 16 12:04:28 2005
@@ -53,11 +53,44 @@
         
self.assertEquals(self.cleanupXMLForTesting(etree.tostring(selector.ob)),
          '<selector><value>div.class</value><commands/></selector>')
 
-    def test_setHtmlAsChild(self):
+    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>')
+         '<selectors><selector><value>div.class</value><commands>' \
+         '<command><name>setHtmlAsChild</name><data name="html">' \
+         'new_content</data></command></commands></selector>' \
+         '</selectors>')
+
+    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>')
+
+    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>')
+
+    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()
@@ -70,9 +103,7 @@
         response = FakeResponse()
         ob = AzaxResponse(response)
         ob.setHtmlAsChild('div.class', 'new_content')
-        self.assertEquals(self.cleanupXMLForTesting(ob()),
-         
'<selectors><selector><value>div.class</value><commands><command><name>setHtmlAsChild</name><data
 name="html">new_content</data></command></commands></selector></selectors>')
-
+        ob()
         self.assertEquals(response._stuff['Content-Type'], 'text/xml')
 
 def test_suite():
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to