[Zope3-checkins] SVN: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/ more tests, some renaming

Andreas Jung andreas at andreas-jung.com
Fri Oct 7 06:32:57 EDT 2005


Log message for revision 38860:
  more tests, some renaming
  

Changed:
  D   Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/publicationfactories.py
  A   Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationfactories.py
  U   Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationregistry.py

-=-
Deleted: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/publicationfactories.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/publicationfactories.py	2005-10-07 10:19:37 UTC (rev 38859)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/publicationfactories.py	2005-10-07 10:32:56 UTC (rev 38860)
@@ -1,83 +0,0 @@
-##############################################################################
-#
-# 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: publicationfactories.py 38841 2005-10-07 04:34:09Z andreasjung $
-"""
-__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
-from zope.app.publication.xmlrpc import XMLRPCPublication
-from zope.app.publication.http import HTTPPublication
-from zope.publisher.xmlrpc import XMLRPCRequest
-from zope.app.publication.browser import BrowserPublication 
-from zope.publisher.http import HTTPRequest
-from zope.publisher.browser import BrowserRequest
-
-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 __call__(self):
-        return self.soap_req, SOAPPublication
-
-
-class XMLRPCFactory(object):
-
-    implements(IRequestPublicationFactory)
-
-    def canHandle(self, environment):
-        return True
-
-    def __call__(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 __call__(self):
-        request_class = component.queryUtility(
-            interfaces.IHTTPRequestFactory, default=HTTPRequest)
-        return request_class, HTTPPublication
-
-class BrowserFactory(object):
-
-    implements(IRequestPublicationFactory)
-
-    def canHandle(self, environment):
-        return True
-
-    def __call__(self):
-        request_class = component.queryUtility(
-                interfaces.IBrowserRequestFactory, default=BrowserRequest)
-        return request_class, BrowserPublication
-

Added: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationfactories.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationfactories.py	2005-10-07 10:19:37 UTC (rev 38859)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationfactories.py	2005-10-07 10:32:56 UTC (rev 38860)
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# 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: publicationfactories.py 38841 2005-10-07 04:34:09Z andreasjung $
+"""
+__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
+from zope.app.publication.xmlrpc import XMLRPCPublication
+from zope.app.publication.http import HTTPPublication
+from zope.publisher.xmlrpc import XMLRPCRequest
+from zope.app.publication.browser import BrowserPublication 
+from zope.publisher.http import HTTPRequest
+from zope.publisher.browser import BrowserRequest
+
+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 __call__(self):
+        return self.soap_req, SOAPPublication
+
+
+class XMLRPCFactory(object):
+
+    implements(IRequestPublicationFactory)
+
+    def canHandle(self, environment):
+        return True
+
+    def __call__(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 __call__(self):
+        request_class = component.queryUtility(
+            interfaces.IHTTPRequestFactory, default=HTTPRequest)
+        return request_class, HTTPPublication
+
+class BrowserFactory(object):
+
+    implements(IRequestPublicationFactory)
+
+    def canHandle(self, environment):
+        return True
+
+    def __call__(self):
+        request_class = component.queryUtility(
+                interfaces.IBrowserRequestFactory, default=BrowserRequest)
+        return request_class, BrowserPublication
+

Modified: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationregistry.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationregistry.py	2005-10-07 10:19:37 UTC (rev 38859)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationregistry.py	2005-10-07 10:32:56 UTC (rev 38860)
@@ -25,6 +25,7 @@
 
 from zope.app.publication.interfaces import IRequestPublicationRegistry
 from zope.app.publication.requestpublicationregistry import RequestPublicationRegistry
+from zope.app.publication.requestpublicationfactories import HTTPFactory, SOAPFactory, BrowserFactory, XMLRPCFactory
 
 
 def DummyFactory():
@@ -32,15 +33,11 @@
 
 class Test(PlacelessSetup, TestCase):
 
-    def setUp(self):
-        super(Test, self).setUp()
-        self._registry = RequestPublicationRegistry()
-
     def test_interface(self):
         verifyClass(IRequestPublicationRegistry, RequestPublicationRegistry)
 
     def test_registration(self):
-        r = self._registry
+        r = RequestPublicationRegistry()
         xmlrpc_f = DummyFactory()
         r.register('POST', 'text/xml', 'xmlrpc', 0, xmlrpc_f)
         soap_f = DummyFactory()
@@ -53,8 +50,22 @@
                             ])
         self.assertEqual(r.getFactoriesFor('POST', 'text/html'), None)
 
+    def test_realfactories(self):
+        r = RequestPublicationRegistry()
+        r.register('POST', '*', 'post_fallback', 0, HTTPFactory())
+        r.register('POST', 'text/xml', 'xmlrpc', 1, XMLRPCFactory())
+        r.register('POST', 'text/xml', 'soap', 1, SOAPFactory())
+        r.register('GET', '*', 'http', 0, HTTPFactory())
+        r.register('PUT', '*', 'http', 0, HTTPFactory())
+        r.register('HEAD', '*', 'http', 0, HTTPFactory())
+        r.register('*', '*', 'http', 1, BrowserFactory())
 
+        self.assertEqual(len(r.getFactoriesFor('POST', 'text/xml')) , 2)
+        self.assertEqual(len(r.getFactoriesFor('POST', '*')) , 1)
+        self.assertEqual(r.getFactoriesFor('GET', 'text/html') , None)
+        self.assertEqual(len(r.getFactoriesFor('HEAD', '*')) , 1)
 
+
 def test_suite():
     return TestSuite((
         makeSuite(Test),



More information about the Zope3-Checkins mailing list