[Zope3-checkins]
SVN: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_
required functionality is working,
code needs more comments and polishing
Andreas Jung
andreas at andreas-jung.com
Fri Oct 7 07:20:43 EDT 2005
Log message for revision 38863:
required functionality is working, code needs more comments and polishing
Changed:
D Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_publicationfactories.py
A Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_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/tests/test_publicationfactories.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_publicationfactories.py 2005-10-07 11:18:23 UTC (rev 38862)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_publicationfactories.py 2005-10-07 11:20:42 UTC (rev 38863)
@@ -1,115 +0,0 @@
-##############################################################################
-#
-# 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_publicationfactories.py 38841 2005-10-07 04:34:09Z andreasjung $
-"""
-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, XMLRPCFactory, HTTPFactory, BrowserFactory
-from zope.app.publication.soap import SOAPPublication
-from zope.app.publication.browser import BrowserPublication
-
-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
- factory = SOAPFactory()
- self.assertEqual(factory.canHandle(env), False)
- env['HTTP_SOAPACTION'] = 'server:foo'
- self.assertEqual(factory.canHandle(env), True)
- request, publication = factory()
- 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()
- 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()
- self.assertEqual(isinstance(request, DummyRequestFactory), True)
- self.assertEqual(publication, HTTPPublication)
-
- def test_browserfactory(self):
- browserrequestfactory = DummyRequestFactory()
- interface.directlyProvides(
- browserrequestfactory, interfaces.IBrowserRequestFactory)
- component.provideUtility(browserrequestfactory)
- env = self.__env
- factory = BrowserFactory()
- self.assertEqual(factory.canHandle(env), True)
- request, publication = factory()
- self.assertEqual(isinstance(request, DummyRequestFactory), True)
- self.assertEqual(publication, BrowserPublication)
-
-def test_suite():
- return TestSuite((
- makeSuite(Test),
- ))
-
-if __name__=='__main__':
- main(defaultTest='test_suite')
Added: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationfactories.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationfactories.py 2005-10-07 11:18:23 UTC (rev 38862)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationfactories.py 2005-10-07 11:20:42 UTC (rev 38863)
@@ -0,0 +1,115 @@
+##############################################################################
+#
+# 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_publicationfactories.py 38841 2005-10-07 04:34:09Z andreasjung $
+"""
+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.requestpublicationfactories import SOAPFactory, XMLRPCFactory, HTTPFactory, BrowserFactory
+from zope.app.publication.soap import SOAPPublication
+from zope.app.publication.browser import BrowserPublication
+
+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
+ factory = SOAPFactory()
+ self.assertEqual(factory.canHandle(env), False)
+ env['HTTP_SOAPACTION'] = 'server:foo'
+ self.assertEqual(factory.canHandle(env), True)
+ request, publication = factory()
+ 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()
+ 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()
+ self.assertEqual(isinstance(request, DummyRequestFactory), True)
+ self.assertEqual(publication, HTTPPublication)
+
+ def test_browserfactory(self):
+ browserrequestfactory = DummyRequestFactory()
+ interface.directlyProvides(
+ browserrequestfactory, interfaces.IBrowserRequestFactory)
+ component.provideUtility(browserrequestfactory)
+ env = self.__env
+ factory = BrowserFactory()
+ self.assertEqual(factory.canHandle(env), True)
+ request, publication = factory()
+ self.assertEqual(isinstance(request, DummyRequestFactory), True)
+ self.assertEqual(publication, BrowserPublication)
+
+def test_suite():
+ return TestSuite((
+ makeSuite(Test),
+ ))
+
+if __name__=='__main__':
+ main(defaultTest='test_suite')
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 11:18:23 UTC (rev 38862)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/tests/test_requestpublicationregistry.py 2005-10-07 11:20:42 UTC (rev 38863)
@@ -23,6 +23,7 @@
from zope.interface.verify import verifyClass
from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.app.publication import interfaces
from zope.app.publication.interfaces import IRequestPublicationRegistry
from zope.app.publication.requestpublicationregistry import RequestPublicationRegistry
from zope.app.publication.requestpublicationfactories import HTTPFactory, SOAPFactory, BrowserFactory, XMLRPCFactory
@@ -31,6 +32,15 @@
def DummyFactory():
return object
+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 test_interface(self):
@@ -45,8 +55,9 @@
browser_f = DummyFactory()
r.register('*', '*', 'browser_default', 0, browser_f)
l = r.getFactoriesFor('POST', 'text/xml')
- self.assertEqual(l, [{'name' : 'xmlrpc', 'priority' : 0, 'factory' : object},
+ self.assertEqual(l, [
{'name' : 'soap', 'priority' : 1, 'factory' : object},
+ {'name' : 'xmlrpc', 'priority' : 0, 'factory' : object},
])
self.assertEqual(r.getFactoriesFor('POST', 'text/html'), None)
@@ -54,7 +65,7 @@
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('POST', 'text/xml', 'soap', 2, SOAPFactory())
r.register('GET', '*', 'http', 0, HTTPFactory())
r.register('PUT', '*', 'http', 0, HTTPFactory())
r.register('HEAD', '*', 'http', 0, HTTPFactory())
@@ -65,7 +76,23 @@
self.assertEqual(r.getFactoriesFor('GET', 'text/html') , None)
self.assertEqual(len(r.getFactoriesFor('HEAD', '*')) , 1)
+ env = {
+ 'SERVER_URL': 'http://127.0.0.1',
+ 'HTTP_HOST': '127.0.0.1',
+ 'CONTENT_LENGTH': '0',
+ 'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
+ }
+ soaprequestfactory = DummyRequestFactory()
+ interface.directlyProvides(
+ soaprequestfactory, interfaces.ISOAPRequestFactory)
+ component.provideUtility(soaprequestfactory)
+
+ self.assertEqual(isinstance(r.lookup('POST', 'text/xml', env), XMLRPCFactory), True)
+ env['HTTP_SOAPACTION'] = 'foo'
+ self.assertEqual(isinstance(r.lookup('POST', 'text/xml', env), SOAPFactory), True)
+ self.assertEqual(isinstance(r.lookup('FOO', 'zope/sucks', env), BrowserFactory), True)
+
def test_suite():
return TestSuite((
makeSuite(Test),
More information about the Zope3-Checkins
mailing list