[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/server/tests/test_server.py
Added unit test for ServerFactory.
Marius Gedminas
marius at pov.lt
Wed Feb 16 12:33:17 EST 2005
Log message for revision 29164:
Added unit test for ServerFactory.
Changed:
A Zope3/trunk/src/zope/app/server/tests/test_server.py
-=-
Added: Zope3/trunk/src/zope/app/server/tests/test_server.py
===================================================================
--- Zope3/trunk/src/zope/app/server/tests/test_server.py 2005-02-16 17:13:31 UTC (rev 29163)
+++ Zope3/trunk/src/zope/app/server/tests/test_server.py 2005-02-16 17:33:17 UTC (rev 29164)
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# Copyright (c) 2005 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 zope.app.server.server
+
+$Id$
+"""
+import unittest
+
+from zope.interface.verify import verifyObject
+from zope.testing import doctest
+from zope.app.testing import ztapi, setup
+
+
+def doctest_ServerFactory():
+ r"""Tests for ServerFactory
+
+ Zope 3 has many server types -- HTTP, FTP, HTTP with postmortem debugging,
+ etc. All of them are registered as IServerType utilities in ZCML.
+
+ >>> setup.placelessSetUp()
+
+ >>> from zope.interface import implements
+ >>> from zope.app.server.servertype import IServerType
+ >>> class MyServerType:
+ ... implements(IServerType)
+ ... def create(self, name, task_dispatcher, db, port='unknown',
+ ... verbose='unspecified', ip=''):
+ ... if not ip:
+ ... ip = '*' # listen on all interfaces
+ ... return ('%s server on %s:%d, registered with %s,\n'
+ ... 'serving from %s, verbosity %s'
+ ... % (name, ip, port, task_dispatcher, db, verbose))
+ >>> ztapi.provideUtility(IServerType, MyServerType(), name='HTTP')
+ >>> ztapi.provideUtility(IServerType, MyServerType(), name='FTP')
+
+ ServerFactory is used to hook into ZConfig and create instances of servers
+ specified in zope.conf. It gets a `section` argument that contains
+ settings specified in a ZConfig <server> section.
+
+ >>> class ServerSectionStub:
+ ... type = 'HTTP'
+ ... address = ('', 8080)
+ ... verbose = False
+ >>> my_section = ServerSectionStub()
+
+ >>> from zope.app.server.server import ServerFactory
+ >>> sf = ServerFactory(my_section)
+
+ The server factory object knows how to create a server, given a task
+ dispatcher (see IDispatcher from zope.server.interfaces) and a ZODB
+ database object.
+
+ >>> task_dispatcher = 'my task dispatcher'
+ >>> db = 'my db'
+ >>> print sf.create(task_dispatcher, db)
+ HTTP server on *:8080, registered with my task dispatcher,
+ serving from my db, verbosity False
+
+ The settings actually work
+
+ >>> my_section.type = 'FTP'
+ >>> my_section.address = ('', 8021)
+ >>> my_section.verbose = True
+ >>> sf = ServerFactory(my_section)
+ >>> print sf.create(task_dispatcher, db)
+ FTP server on *:8021, registered with my task dispatcher,
+ serving from my db, verbosity True
+
+ That's it.
+
+ >>> setup.placelessTearDown()
+
+ """
+
+
+def test_suite():
+ return doctest.DocTestSuite()
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: Zope3/trunk/src/zope/app/server/tests/test_server.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list