[Zope3-checkins] SVN: Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/ refactored SOAPFactory...more to follow

Andreas Jung andreas at andreas-jung.com
Thu Oct 6 12:32:39 EDT 2005


Log message for revision 38805:
  refactored SOAPFactory...more to follow
  

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

-=-
Added: 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:30:43 UTC (rev 38804)
+++ Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/publicationfactories.py	2005-10-06 16:32:38 UTC (rev 38805)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Publication factories.
+
+This module provides factories for tuples (request, publication).
+
+$Id: xmlrpc.py 27311 2004-08-27 21:22:43Z jim $
+"""
+__docformat__ = 'restructuredtext'
+
+from zope import component
+from zope.interface import implements
+from zope.app.publication.http import BaseHTTPPublication
+from zope.app.publication.interfaces import IRequestPublicationFactory, ISOAPRequestFactory, ISOAPRequestFactory
+from zope.app.publication import interfaces
+from zope.app.publication.soap import SOAPPublication
+
+class SOAPFactory(object):
+
+    implements(IRequestPublicationFactory)
+
+    def canHandle(self, environment):
+        self.soap_req = component.queryUtility(interfaces.ISOAPRequestFactory)
+        return bool(environment.get('HTTP_SOAPACTION') and self.soap_req)
+
+    def getRequestPublication(self):
+        return self.soap_req, SOAPPublication
+

Added: 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:30:43 UTC (rev 38804)
+++ Zope3/branches/ajung-tarek-request-publication-branch/src/zope/app/publication/tests/test_publicationfactories.py	2005-10-06 16:32:38 UTC (rev 38805)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Tests for the HTTP Publication Request Factory.
+
+$Id: test_httpfactory.py 38357 2005-09-07 20:14:34Z srichter $
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from StringIO import StringIO
+
+from zope import component, interface
+from zope.publisher.browser import BrowserRequest
+from zope.publisher.http import HTTPRequest
+from zope.publisher.xmlrpc import XMLRPCRequest
+from zope.component.tests.placelesssetup import PlacelessSetup
+
+from zope.app.publication.httpfactory import HTTPPublicationRequestFactory
+from zope.app.publication.browser import BrowserPublication
+from zope.app.publication.http import HTTPPublication
+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.soap import SOAPPublication
+
+class DummyRequestFactory(object):
+    def __call__(self, input_stream, env):
+        self.input_stream = input_stream
+        self.env = env
+        return self
+
+    def setPublication(self, pub):
+        self.pub = pub
+ 
+
+class Test(PlacelessSetup, TestCase):
+
+    def setUp(self):
+        super(Test, self).setUp()
+        self.__env =  {
+            'SERVER_URL':         'http://127.0.0.1',
+            'HTTP_HOST':          '127.0.0.1',
+            'CONTENT_LENGTH':     '0',
+            'GATEWAY_INTERFACE':  'TestFooInterface/1.0',
+            }
+
+    def test_soapfactory(self):
+        soaprequestfactory = DummyRequestFactory()
+        interface.directlyProvides(
+            soaprequestfactory, interfaces.ISOAPRequestFactory)
+        component.provideUtility(soaprequestfactory)
+        env = self.__env
+        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_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')



More information about the Zope3-Checkins mailing list