[Zope-Checkins] CVS: Zope3/lib/python/Zope/StartUp/tests - testRegisterRequestFactory.py:1.1.2.1 testRegisterServerType.py:1.1.2.1 testRequestFactoryRegistry.py:1.1.2.1 testServerTypeRegistry.py:1.1.2.1 __init__.py:1.1.2.2 testStartupDirectives.py:1.1.2.2

Stephan Richter srichter@cbu.edu
Sat, 30 Mar 2002 02:02:16 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/StartUp/tests
In directory cvs.zope.org:/tmp/cvs-serv25616/lib/python/Zope/StartUp/tests

Modified Files:
      Tag: Zope-3x-branch
	__init__.py testStartupDirectives.py 
Added Files:
      Tag: Zope-3x-branch
	testRegisterRequestFactory.py testRegisterServerType.py 
	testRequestFactoryRegistry.py testServerTypeRegistry.py 
Log Message:
I played with the startup directives some more and separated the programmer
directives from the site admins. One can now easily create new sites
without knowing anything about Zope. The only thing s/he has to know is the
name of the server (i.e. Browser) s/he wants to start for a particular
site.

There is also registries now for RequestFactories and and ServerTypes, so 
that third party programmers can easily add their own request factories and
server types to the system by calling a couple of directives. That makes it
also really plugable, since one could simply exchange the Logger of a server
without much hassle.

Also, each storage type has its own directive now, since arguments for the
constructors of the storages greatly vary. 

Note: The directives now are probably not flexible enough for future use,
      but we can add complexity as we need it later.  



=== Added File Zope3/lib/python/Zope/StartUp/tests/testRegisterRequestFactory.py ===
##############################################################################
#
# 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.0 (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.
# 
##############################################################################
"""

$Id: testRegisterRequestFactory.py,v 1.1.2.1 2002/03/30 07:02:15 srichter Exp $
"""

import unittest
from Zope.StartUp.RequestFactoryRegistry import getRequestFactory

from Zope.Configuration.xmlconfig import xmlconfig
from cStringIO import StringIO


template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:startup='http://namespaces.zope.org/startup'>
   %s
   </zopeConfigure>"""


class Test( unittest.TestCase ):


    def testRegisterRequestFactory(self):

        xmlconfig(StringIO(template % (
            '''
            <directive name="registerRequestFactory"
               attributes="name, publication, request"
               handler="Zope.StartUp.metaConfigure.registerRequestFactory"
               namespace="http://namespaces.zope.org/startup" />

            <startup:registerRequestFactory name="BrowserRequestFactory"
              publication = 
              "Zope.App.ZopePublication.Browser.Publication.BrowserPublication"
              request = "Zope.Publisher.Browser.BrowserRequest." />
            '''
            )))

        from Zope.App.ZopePublication.Browser.Publication import \
             BrowserPublication
        from Zope.Publisher.Browser.BrowserRequest import BrowserRequest

        self.assertEqual(
            getRequestFactory('BrowserRequestFactory')._pubFactory,
            BrowserPublication)
        self.assertEqual(
            getRequestFactory('BrowserRequestFactory')._request,
            BrowserRequest)



def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )


if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )



=== Added File Zope3/lib/python/Zope/StartUp/tests/testRegisterServerType.py ===
##############################################################################
#
# 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.0 (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.
# 
##############################################################################
"""

$Id: testRegisterServerType.py,v 1.1.2.1 2002/03/30 07:02:15 srichter Exp $
"""

import unittest
from Zope.StartUp.ServerTypeRegistry import getServerType

from Zope.Configuration.xmlconfig import xmlconfig
from cStringIO import StringIO


template = """<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:startup='http://namespaces.zope.org/startup'>
   %s
   </zopeConfigure>"""


class Test( unittest.TestCase ):


    def testRegisterServerType(self):

        xmlconfig(StringIO(template % (
            '''<directive name="registerServerType"
                 attributes="name, publication, request"
                 handler="Zope.StartUp.metaConfigure.registerServerType"
                 namespace="http://namespaces.zope.org/startup" />

               <startup:registerServerType 
                 name = "Browser"
                 factory = "Zope.Server.PublisherServers.PublisherHTTPServer"
                 requestFactory="BrowserRequestFactory"
                 logFactory = "Zope.Server.HTTPServer.CommonHitLogger"
                 defaultPort="8080"
                 defaultVerbose="true" />
            '''
            )))

        from Zope.Server.PublisherServers import PublisherHTTPServer
        from Zope.Server.HTTPServer import CommonHitLogger

        self.assertEqual(getServerType('Browser')._factory,
                         PublisherHTTPServer)
        self.assertEqual(getServerType('Browser')._logFactory, CommonHitLogger)
        self.assertEqual(getServerType('Browser')._requestFactory,
                         "BrowserRequestFactory")
        self.assertEqual(getServerType('Browser')._defaultPort, 8080)
        self.assertEqual(getServerType('Browser')._defaultVerbose, 1)



def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )


if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )



=== Added File Zope3/lib/python/Zope/StartUp/tests/testRequestFactoryRegistry.py ===
##############################################################################
#
# 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.0 (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.
# 
##############################################################################
"""
I do not think it is necessary to do the entire SimpleRegistry tests again.
Instead we will test whether the module in itself works.

$Id: testRequestFactoryRegistry.py,v 1.1.2.1 2002/03/30 07:02:15 srichter Exp $
"""

import unittest
from Zope.StartUp.RequestFactoryRegistry import \
     registerRequestFactory, getRequestFactory
from Zope.StartUp.RequestFactory import IRequestFactory


class RequestFactory:
    """RequestFactory Stub."""

    __implements__ = IRequestFactory



class Test( unittest.TestCase ):


    def testRegistry(self):

        factory = RequestFactory()

        registerRequestFactory('factory', factory)
        self.assertEqual(getRequestFactory('factory'), factory)
        

def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )


if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )



=== Added File Zope3/lib/python/Zope/StartUp/tests/testServerTypeRegistry.py ===
##############################################################################
#
# 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.0 (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.
# 
##############################################################################
"""
I do not think it is necessary to do the entire SimpleRegistry tests again.
Instead we will test whether the module in itself works.

$Id: testServerTypeRegistry.py,v 1.1.2.1 2002/03/30 07:02:15 srichter Exp $
"""

import unittest
from Zope.StartUp.ServerTypeRegistry import \
     registerServerType, getServerType
from Zope.StartUp.ServerType import IServerType


class ServerType:
    """ServerType Stub."""

    __implements__ = IServerType



class Test( unittest.TestCase ):


    def testRegistry(self):

        server = ServerType()

        registerServerType('server', server)
        self.assertEqual(getServerType('server'), server)
        

def test_suite():
    loader = unittest.TestLoader()
    return loader.loadTestsFromTestCase( Test )


if __name__=='__main__':
    unittest.TextTestRunner().run( test_suite() )



=== Zope3/lib/python/Zope/StartUp/tests/__init__.py 1.1.2.1 => 1.1.2.2 ===


=== Zope3/lib/python/Zope/StartUp/tests/testStartupDirectives.py 1.1.2.1 => 1.1.2.2 ===
     
 
-    def testStorageMethod(self):
-        """Note: I could not name the test testUseStorage, since another
-           test would throw errors."""
+    def testStorageMethods(self):
+        """ """
         sd = self._createBlankSiteDefinition()
 
-        self.assertEqual(sd.useStorage(ContextStub()), [])
+        self.assertEqual(sd.useFileStorage(ContextStub()), [])
         self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
         self.assertEqual(sd._zodb._storage._file_name, 'Data.fs')
         sd._zodb.close()
         
         filename = tempfile.mktemp()
-        self.assertEqual(sd.useStorage(ContextStub(), file=filename), [])
+        self.assertEqual(sd.useFileStorage(ContextStub(), file=filename), [])
         self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
         self.assertEqual(sd._zodb._storage._file_name, filename)
         sd._zodb.close()
 
-        # XXX: There should be more tests here for other Storage types. I just
-        #      do not know enough about it.
+        self.assertEqual(sd.useMappingStorage(ContextStub()), [])
+        self.assertEqual(sd._zodb._storage.__class__.__name__,
+                         'MappingStorage')
 
 
     def testUseLog(self):
@@ -78,23 +78,13 @@
 
         from Zope.Configuration.Action import Action
 
-        self.assertEqual(sd.addServer(ContextStub()),
-                         [ Action(discriminator = 'Start Servers',
-                                  callable = sd.start,
-                                  args = (),
-                                  ) ]
-                         )
+        self.assertEqual(sd.addServer(ContextStub(), 'Browser',
+                                      '8081', 'true'), [])
         self.assertEqual(len(sd._servers), 1)
         self.assertEqual(sd._servers.keys(), ['Browser'])
 
         server_info = sd._servers['Browser']
-        server_type = sd._server_types['Browser']
-        self.assertEqual(server_info['server'], server_type[0])
-        self.assertEqual(server_info['publication'], server_type[1])
-        self.assertEqual(server_info['request'], server_type[2])
         self.assertEqual(server_info['port'], 8081)
-        self.assertEqual(server_info['logClass'],
-                         resolve('Zope.Server.HTTPServer.CommonHitLogger'))
         self.assertEqual(server_info['verbose'], 1)
 
 
@@ -108,7 +98,7 @@
         from Zope.App.ZopePublication.ZopePublication import ZopePublication
 
         filename = tempfile.mktemp()
-        sd.useStorage(ContextStub(), file=filename)
+        sd.useFileStorage(ContextStub(), file=filename)
 
         connection = sd._zodb.open()
         root = connection.root()