瀏覽代碼

HUE-1632 [oozie] Workflow with & in a property fail to submit

Abraham Elmahrek 12 年之前
父節點
當前提交
a3a8cfcfd6

+ 1 - 1
desktop/core/src/desktop/lib/test_utils.py

@@ -56,6 +56,6 @@ def reformat_json(json_obj):
 
 def reformat_xml(xml_obj):
     if isinstance(xml_obj, basestring):
-        return etree.tostring(objectify.fromstring(xml_obj))
+        return etree.tostring(objectify.fromstring(xml_obj, etree.XMLParser(strip_cdata=False, remove_blank_text=True)))
     else:
         return etree.tostring(xml_obj)

+ 20 - 0
desktop/libs/liboozie/src/liboozie/tests.py

@@ -20,7 +20,10 @@ import logging
 from nose.tools import assert_equal
 from oozie.tests import MockOozieApi
 
+from desktop.lib.test_utils import reformat_xml
+
 from liboozie.types import WorkflowAction, Coordinator
+from liboozie.utils import config_gen
 
 
 LOG = logging.getLogger(__name__)
@@ -36,3 +39,20 @@ def test_valid_external_id():
 def aggregate_coordinator_instances():
   dates = ['1', '2', '3', '6', '7', '8', '10', '12', '15', '16', '20', '23', '30', '40']
   assert_equal(['1-3', '6-8', '10-10', '12-12', '15-16', '20-20', '23-23', '30-30', '40-40'], Coordinator.aggreate(dates))
+
+
+def test_config_gen():
+  properties = {
+    'user.name': 'hue',
+    'test.1': 'http://localhost/test?test1=test&test2=test'
+  }
+  assert_equal(reformat_xml("""<configuration>
+<property>
+  <name>test.1</name>
+  <value><![CDATA[http://localhost/test?test1=test&test2=test]]></value>
+</property>
+<property>
+  <name>user.name</name>
+  <value><![CDATA[hue]]></value>
+</property>
+</configuration>"""), reformat_xml(config_gen(properties)))

+ 1 - 1
desktop/libs/liboozie/src/liboozie/utils.py

@@ -56,7 +56,7 @@ def config_gen(dic):
   print >> sio, '<?xml version="1.0" encoding="UTF-8"?>'
   print >> sio, "<configuration>"
   for k, v in dic.iteritems():
-    print >> sio, "<property>\n  <name>%s</name>\n  <value>%s</value>\n</property>\n" \
+    print >> sio, "<property>\n  <name>%s</name>\n  <value><![CDATA[%s]]></value>\n</property>\n" \
         % (k, v)
   print >>sio, "</configuration>"
   sio.flush()