[Zope-Checkins] CVS: Zope/lib/python/ZServer/tests - test_responses.py:1.1.2.1.4.4

Chris McDonough chrism at plope.com
Sun Mar 28 01:12:13 EST 2004


Update of /cvs-repository/Zope/lib/python/ZServer/tests
In directory cvs.zope.org:/tmp/cvs-serv9701/ZServer/tests

Modified Files:
      Tag: chrism-publishfile-branch
	test_responses.py 
Log Message:
Instead of returning a producer directly, return a StreamIterator which is then turned into a producer.  This provides better encapsulation, as Zope app code won't depend on ZServer in places where it returns an iterator (instead it will depend only on ZPublisher).


=== Zope/lib/python/ZServer/tests/test_responses.py 1.1.2.1.4.3 => 1.1.2.1.4.4 ===
--- Zope/lib/python/ZServer/tests/test_responses.py:1.1.2.1.4.3	Wed Mar 24 02:49:06 2004
+++ Zope/lib/python/ZServer/tests/test_responses.py	Sun Mar 28 01:12:10 2004
@@ -18,7 +18,7 @@
 from ZServer.FTPResponse import FTPResponse
 from ZServer.PCGIServer import PCGIResponse
 from ZServer.FCGIServer import FCGIResponse
-from ZServer.Producers import IZServerProducer
+from ZPublisher.Iterators import IStreamIterator
 import unittest
 from cStringIO import StringIO
 
@@ -41,33 +41,21 @@
         response = FCGIResponse()
         self.assertRaises(TypeError, response.write, u'bad')
 
-    def test_setBodyProducer(self):
-        _BODY = 'hello'
+    def test_setBodyIterator(self):
         channel = DummyChannel()
         one = ZServerHTTPResponse(stdout=channel)
         one.setHeader('content-length', 5)
-        one.setBody(dummy_producer(_BODY))
+        one.setBody(test_streamiterator())
         one.outputBody()
         all = channel.all()
         lines = all.split('\r\n')
         self.assertEqual(lines[-2], '')    # end of headers
-        self.assertEqual(lines[-1], _BODY) # payload
+        self.assertEqual(lines[-1], 'hello') # payload
 
-    def test_setBodyProducerFailsWithoutContentLength(self):
+    def test_setBodyIteratorFailsWithoutContentLength(self):
         one = ZServerHTTPResponse(stdout=DummyChannel())
         self.assertRaises(AssertionError,
-                          one.setBody, dummy_producer("hello"))
-
-class dummy_producer:
-    __implements__ = (IZServerProducer,)
-    def __init__(self, data):
-        self.data = data
-        self._done = 0
-        
-    def more(self):
-        if not self._done:
-            self._done = 1
-            return self.data
+                          one.setBody, test_streamiterator())
 
 class DummyChannel:
     def __init__(self):
@@ -92,6 +80,17 @@
             if not s:
                 break
             self.out.write(s)
+
+class test_streamiterator:
+    __implements__ = IStreamIterator
+    data = "hello"
+    done = 0
+
+    def next(self):
+        if not self.done:
+            self.done = 1
+            return self.data
+        raise StopIteration
 
 def test_suite():
     return unittest.makeSuite(ZServerResponseTestCase)




More information about the Zope-Checkins mailing list