[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/server/ Added a unit
test for zope.app.server.servertype.ServerType. Fixed the
Marius Gedminas
marius at pov.lt
Wed Feb 16 12:01:29 EST 2005
Log message for revision 29162:
Added a unit test for zope.app.server.servertype.ServerType. Fixed the
signature of IServerType.create to match reality.
Changed:
U Zope3/trunk/src/zope/app/server/servertype.py
A Zope3/trunk/src/zope/app/server/tests/test_servertype.py
-=-
Modified: Zope3/trunk/src/zope/app/server/servertype.py
===================================================================
--- Zope3/trunk/src/zope/app/server/servertype.py 2005-02-16 16:23:39 UTC (rev 29161)
+++ Zope3/trunk/src/zope/app/server/servertype.py 2005-02-16 17:01:23 UTC (rev 29162)
@@ -23,7 +23,7 @@
a ZCML directive and we shouldn't be able to change them.
"""
- def create(task_dispatcher, db, port=None, verbose=None):
+ def create(name, task_dispatcher, db, port=None, verbose=None):
"""Create the server knowing the port, task dispatcher and the ZODB.
Returns the new server.
Added: Zope3/trunk/src/zope/app/server/tests/test_servertype.py
===================================================================
--- Zope3/trunk/src/zope/app/server/tests/test_servertype.py 2005-02-16 16:23:39 UTC (rev 29161)
+++ Zope3/trunk/src/zope/app/server/tests/test_servertype.py 2005-02-16 17:01:23 UTC (rev 29162)
@@ -0,0 +1,116 @@
+##############################################################################
+#
+# 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.servertype
+
+$Id$
+"""
+import unittest
+
+from zope.interface.verify import verifyObject
+from zope.testing import doctest
+
+
+def doctest_ServerType():
+ r"""Tests for ServerType
+
+ Zope 3 has many server types -- HTTP, FTP, HTTP with postmortem debugging,
+ etc. All of them are registered as IServerType utilities in ZCML.
+
+ ServerType is an implementation of IServerType. The constructor of
+ ServerType takes quite a few arguments, a number of which are factories.
+ We will use stubs of those.
+
+ The 'factory' argument specifies the server factory (e.g.
+ PublisherHTTPServer from zope.server.http.httpserver)
+
+ >>> def factory(request_factory, name, ip, port,
+ ... task_dispatcher=None, hit_log=None, verbose=False):
+ ... if ip == '':
+ ... ip = '*' # listen on all network interfaces
+ ... print "Starting a server (%s) on %s:%d" % (name, ip, port)
+ ... print "This server will use %s to construct requests" % \
+ ... request_factory
+ ... print "This server will use %s for hit logging" % hit_log
+ ... if verbose:
+ ... print "This server will be verbose"
+ ... else:
+ ... print "This server will not be verbose"
+ ... print "This server will be managed by %s" % task_dispatcher
+
+ The 'requestFactory' argument specifies a function that returns a factory
+ for requests (e.g. HTTPPublicationRequestFactory from
+ zope.server.http.publisherhttpserver). It is, in fact, a request factory
+ factory.
+
+ >>> def requestFactory(db):
+ ... return 'my request factory for %s' % db
+
+ The 'logFactory' argument specifies the factory for an access logger (e.g.
+ CommonAccessLogger from zope.server.http.commonaccesslogger).
+
+ >>> def logFactory():
+ ... return 'my logger'
+
+ The 'defaultPort' argument specifies the default TCP port number for the
+ server.
+
+ The 'defaultVerbose' argument specifies the default verbosity.
+
+ >>> from zope.app.server.servertype import IServerType
+ >>> from zope.app.server.servertype import ServerType
+ >>> st = ServerType(factory, requestFactory, logFactory,
+ ... defaultPort=8080, defaultVerbose=False)
+ >>> verifyObject(IServerType, st)
+ True
+
+ A server type is then registered as a named utility. These utilities are
+ used while interpreting <server> sections of zope.conf to create instances
+ of servers listening on a specific port.
+
+ When you create an instance of a server, you need to tell it the task
+ dispatcher (see IDispatcher in zope.server.interfaces), and the ZODB
+ database object.
+
+ The `name` argument to create is, as far as I can tell, purely informative.
+ It is used to construct a server identifier that appears in log files and,
+ for example, the 'Server' HTTP header.
+
+ >>> dispatcher = 'my task dispatcher'
+ >>> db = 'my database'
+ >>> st.create('Sample Server', dispatcher, db)
+ Starting a server (Sample Server) on *:8080
+ This server will use my request factory for my database to construct requests
+ This server will use my logger for hit logging
+ This server will not be verbose
+ This server will be managed by my task dispatcher
+
+ You can, of course, create multiple instances of the same server type, and
+ bind them to different ports.
+
+ >>> st.create('Sample Server 2', dispatcher, db, port=1234, verbose=True)
+ Starting a server (Sample Server 2) on *:1234
+ This server will use my request factory for my database to construct requests
+ This server will use my logger for hit logging
+ This server will be verbose
+ This server will be managed by my task dispatcher
+
+ """
+
+
+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_servertype.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zope3-Checkins
mailing list