[Zope3-checkins] SVN: Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/ added HTTPFactory

Andreas Jung andreas at andreas-jung.com
Thu Oct 6 13:03:29 EDT 2005


Log message for revision 38812:
  added HTTPFactory
  

Changed:
  U   Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/publicationfactories.py
  U   Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/tests/test_publicationfactories.py

-=-
Modified: Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/publicationfactories.py
===================================================================
--- Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/publicationfactories.py	2005-10-06 16:53:56 UTC (rev 38811)
+++ Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/publicationfactories.py	2005-10-06 17:03:29 UTC (rev 38812)
@@ -25,6 +25,10 @@
 from zope.app.publication.interfaces import IRequestPublicationFactory, ISOAPRequestFactory, ISOAPRequestFactory
 from zope.app.publication import interfaces
 from zope.app.publication.soap import SOAPPublication
+from zope.app.publication.xmlrpc import XMLRPCPublication
+from zope.app.publication.http import HTTPPublication
+from zope.publisher.xmlrpc import XMLRPCRequest
+from zope.publisher.http import HTTPRequest
 
 class SOAPFactory(object):
 
@@ -37,3 +41,29 @@
     def getRequestPublication(self):
         return self.soap_req, SOAPPublication
 
+
+class XMLRPCFactory(object):
+
+    implements(IRequestPublicationFactory)
+
+    def canHandle(self, environment):
+        return True
+
+    def getRequestPublication(self):
+        request_class = component.queryUtility(
+            interfaces.IXMLRPCRequestFactory, default=XMLRPCRequest)
+        return request_class, XMLRPCPublication
+
+
+class HTTPFactory(object):
+
+    implements(IRequestPublicationFactory)
+
+    def canHandle(self, environment):
+        return True
+
+    def getRequestPublication(self):
+        request_class = component.queryUtility(
+            interfaces.IHTTPRequestFactory, default=HTTPRequest)
+        return request_class, HTTPPublication
+

Modified: Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/tests/test_publicationfactories.py
===================================================================
--- Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/tests/test_publicationfactories.py	2005-10-06 16:53:56 UTC (rev 38811)
+++ Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/tests/test_publicationfactories.py	2005-10-06 17:03:29 UTC (rev 38812)
@@ -31,7 +31,7 @@
 from zope.app.publication.xmlrpc import XMLRPCPublication
 from zope.app.testing import ztapi
 from zope.app.publication import interfaces
-from zope.app.publication.publicationfactories import SOAPFactory 
+from zope.app.publication.publicationfactories import SOAPFactory, XMLRPCFactory, HTTPFactory 
 from zope.app.publication.soap import SOAPPublication
 
 class DummyRequestFactory(object):
@@ -61,13 +61,38 @@
             soaprequestfactory, interfaces.ISOAPRequestFactory)
         component.provideUtility(soaprequestfactory)
         env = self.__env
+        factory = SOAPFactory()
+        self.assertEqual(factory.canHandle(env), False)
         env['HTTP_SOAPACTION'] = 'server:foo'
-        factory = SOAPFactory()
         self.assertEqual(factory.canHandle(env), True)
         request, publication = factory.getRequestPublication()
         self.assertEqual(isinstance(request, DummyRequestFactory), True)
         self.assertEqual(publication, SOAPPublication)
 
+    def test_xmlrpcfactory(self):
+        xmlrpcrequestfactory = DummyRequestFactory()
+        interface.directlyProvides(
+            xmlrpcrequestfactory, interfaces.IXMLRPCRequestFactory)
+        component.provideUtility(xmlrpcrequestfactory)
+        env = self.__env
+        factory = XMLRPCFactory()
+        self.assertEqual(factory.canHandle(env), True)
+        request, publication = factory.getRequestPublication()
+        self.assertEqual(isinstance(request, DummyRequestFactory), True)
+        self.assertEqual(publication, XMLRPCPublication)
+
+    def test_httpfactory(self):
+        httprequestfactory = DummyRequestFactory()
+        interface.directlyProvides(
+            httprequestfactory, interfaces.IHTTPRequestFactory)
+        component.provideUtility(httprequestfactory)
+        env = self.__env
+        factory = HTTPFactory()
+        self.assertEqual(factory.canHandle(env), True)
+        request, publication = factory.getRequestPublication()
+        self.assertEqual(isinstance(request, DummyRequestFactory), True)
+        self.assertEqual(publication, HTTPPublication)
+
 def test_suite():
     return TestSuite((
         makeSuite(Test),



More information about the Zope3-Checkins mailing list