From 163582bf4f85a6e285558f82bd8c192073389fab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Sat, 16 Sep 2006 11:57:34 +0000
Subject: [PATCH] use low-level RESPONSE.write and RESPONSE.flush to flush
 output in runUnitTestList

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10027 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/TemplateTool.py | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/product/ERP5/Tool/TemplateTool.py b/product/ERP5/Tool/TemplateTool.py
index a8d6688da0..9b39e656c7 100644
--- a/product/ERP5/Tool/TemplateTool.py
+++ b/product/ERP5/Tool/TemplateTool.py
@@ -417,15 +417,32 @@ class TemplateTool (BaseTool):
       elif (batch_mode == 1):
         return bt
 
-    def runUnitTestList(self, test_list=[], **kwd):
-      """
-        Runs Unit Tests related to this Business Template
+    security.declareProtected(Permissions.ManagePortal, 'runUnitTestList')
+    def runUnitTestList(self, test_list=[],
+                        REQUEST=None, RESPONSE=None, **kwd):
+      """Runs Unit Tests related to this Business Template
       """
       # XXX: should check for file presence before trying to execute.
       # XXX: should check if the unit test file is configured in the BT
       from Products.ERP5Type.tests.runUnitTest import getUnitTestFile
-      return os.popen('/usr/bin/python %s %s 2>&1'
-                      % (getUnitTestFile(), ' '.join(test_list))).read()
+      if RESPONSE is not None:
+        outfile = RESPONSE
+      elif REQUEST is not None:
+        outfile = RESPONSE = REQUEST.RESPONSE
+      else:
+        outfile =  StringIO()
+      if RESPONSE is not None:
+        RESPONSE.setHeader('Content-type', 'text/plain')
+      process = os.popen('/usr/bin/python %s %s 2>&1'
+                      % (getUnitTestFile(), ' '.join(test_list)))
+      while 1:
+        try:
+          outfile.write(process.next())
+          outfile.flush()
+        except StopIteration:
+          break
+      if hasattr(outfile, 'getvalue'):
+        return outfile.getvalue()
 
     def diffObject(self, REQUEST, **kw):
       """
-- 
2.30.9