[Zope3-checkins] CVS: Zope3/src/zope/app/startup/tests - __init__.py:1.1.2.1 test_registerrequestfactory.py:1.1.2.1 test_registerservertype.py:1.1.2.1 test_requestfactoryregistry.py:1.1.2.1 test_servertyperegistry.py:1.1.2.1 test_simpleregistry.py:1.1.2.1 test_startupdirectives.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:32:32 -0500


Update of /cvs-repository/Zope3/src/zope/app/startup/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/startup/tests

Added Files:
      Tag: NameGeddon-branch
	__init__.py test_registerrequestfactory.py 
	test_registerservertype.py test_requestfactoryregistry.py 
	test_servertyperegistry.py test_simpleregistry.py 
	test_startupdirectives.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/startup/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/startup/tests/test_registerrequestfactory.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: test_registerrequestfactory.py,v 1.1.2.1 2002/12/23 19:32:31 jim Exp $
"""

import unittest
from cStringIO import StringIO
from zope.configuration.xmlconfig import xmlconfig
from zope.configuration.tests.basetestdirectivesxml import makeconfig
from zope.app.startup.requestfactoryregistry import getRequestFactory


class Test( unittest.TestCase ):

    def testRegisterRequestFactory(self):

        xmlconfig(makeconfig(
            '''<directive
                   name="registerRequestFactory"
                   attributes="name publication request"
                   handler=
                   "Zope.App.StartUp.metaConfigure.registerRequestFactory"
                   />''',
            '''<test:registerRequestFactory
                   name="BrowserRequestFactory"
                   publication= 
             "Zope.App.ZopePublication.Browser.Publication.BrowserPublication"
                   request = "Zope.Publisher.Browser.BrowserRequest." />
            '''
            ))

        from zope.app.publication.browser import \
             BrowserPublication
        from zope.publisher.browser 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/src/zope/app/startup/tests/test_registerservertype.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.
# 
##############################################################################
"""terServerType.py,v 1.1.2.2 2002/04/02 02:20:40 srichter Exp $
"""

import unittest
from cStringIO import StringIO
from zope.configuration.xmlconfig import xmlconfig
from zope.configuration.tests.basetestdirectivesxml import makeconfig
from zope.app.startup.servertyperegistry import getServerType


class Test( unittest.TestCase ):

    def testRegisterServerType(self):
        xmlconfig(makeconfig(
            '''<directive
                   name="registerServerType"
                   attributes="name publication request"
                   handler="Zope.App.StartUp.metaConfigure.registerServerType"
                   />''',
            '''<test:registerServerType 
                 name = "Browser"
                 factory = "Zope.Server.HTTP.PublisherHTTPServer."
                 requestFactory="BrowserRequestFactory"
                 logFactory = "Zope.Server.HTTP.CommonHitLogger."
                 defaultPort="8080"
                 defaultVerbose="true" />'''
            ))

        from zope.server.http.publisherhttpserver import PublisherHTTPServer
        from zope.server.http.commonhitlogger 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/src/zope/app/startup/tests/test_requestfactoryregistry.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: test_requestfactoryregistry.py,v 1.1.2.1 2002/12/23 19:32:31 jim Exp $
"""

import unittest
from zope.app.startup.requestfactoryregistry import \
     registerRequestFactory, getRequestFactory
from zope.app.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/src/zope/app/startup/tests/test_servertyperegistry.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: test_servertyperegistry.py,v 1.1.2.1 2002/12/23 19:32:31 jim Exp $
"""

import unittest
from zope.app.startup.servertyperegistry import \
     registerServerType, getServerType
from zope.app.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() )



=== Added File Zope3/src/zope/app/startup/tests/test_simpleregistry.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: test_simpleregistry.py,v 1.1.2.1 2002/12/23 19:32:31 jim Exp $
"""

import unittest
from zope.interface import Interface
from zope.app.startup.simpleregistry import SimpleRegistry, \
     ZopeDuplicateRegistryEntryError, ZopeIllegalInterfaceError


class I1(Interface):
    pass


class I2(Interface):
    pass


class Object1:
    __implements__ = I1


class Object2:
    __implements__ = I2


class Test( unittest.TestCase ):


    def testRegister(self):

        registry = SimpleRegistry(I1)
        obj1 = Object1()

        self.assertEqual(registry.objects, {})
        
        registry.register('obj1', obj1)
        self.assertEqual(registry.objects, {'obj1': obj1})

        registry.register('obj2', obj1)
        self.assertEqual(registry.objects, {'obj1': obj1, 'obj2': obj1})


    def testIllegalInterfaceError(self):

        registry = SimpleRegistry(I1)
        obj2 = Object2()

        self.failUnlessRaises(ZopeIllegalInterfaceError,
                              registry.register, 'obj2', obj2)
        

    def testDuplicateEntry(self):

        registry = SimpleRegistry(I1)
        obj1 = Object1()
        registry.register('obj1', obj1)

        self.failUnlessRaises(ZopeDuplicateRegistryEntryError,
                              registry.register, 'obj1', obj1)
        

    def testGet(self):

        registry = SimpleRegistry(I1)
        obj1 = Object1()
        obj2 = Object1()
        registry.objects = {'obj1': obj1, 'obj2': obj2}

        self.assertEqual(registry.get('obj1'), obj1)
        self.assertEqual(registry.get('obj2'), obj2)

        # Requesting an object that does not exist
        self.assertEqual(registry.get('obj3'), None)
        


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


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



=== Added File Zope3/src/zope/app/startup/tests/test_startupdirectives.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: test_startupdirectives.py,v 1.1.2.1 2002/12/23 19:32:31 jim Exp $
"""

import unittest, sys, tempfile, os
import logging

from zope.app.services.tests.placefulsetup import \
     PlacefulSetup
from zope.app.startup.metaconfigure import SiteDefinition
from zope.configuration.name import resolve
from zope.component.adapter import provideAdapter

_fsname = tempfile.mktemp()+'.fs'

class ContextStub:

    def resolve(self, dottedname):
        return resolve(dottedname)


class Test(PlacefulSetup, unittest.TestCase):

    def tearDown(self):

        PlacefulSetup.tearDown(self)

        for ext in '', '.lock', '.index', '.tmp':
            try: os.remove(_fsname + ext)
            except: pass


    def _createBlankSiteDefinition(self):
        return SiteDefinition('', 'Example Site', 4)


    def testStorageMethods(self):
        sd = self._createBlankSiteDefinition()

        self.assertEqual(sd.useFileStorage(ContextStub(), file=_fsname), [])
        self.assertEqual(sd._zodb._storage.__class__.__name__, 'FileStorage')
        self.assertEqual(sd._zodb._storage._file_name, _fsname)
        sd.close()

        self.assertEqual(sd.useMappingStorage(ContextStub()), [])
        self.assertEqual(sd._zodb._storage.__class__.__name__,
                         'MappingStorage')
        sd.close()


    def testUseLog(self):
        sd = self._createBlankSiteDefinition()

        self.assertEqual(sd.useLog(ContextStub()), [])
        for h in logging.root.handlers:
            if isinstance(h, logging.StreamHandler):
                if h.stream is sys.stderr:
                    break
        else:
            self.fail("Not logging to sys.stderr")

        self.assertEqual(sd.useLog(ContextStub(), _fsname), [])
        for h in logging.root.handlers:
            if isinstance(h, logging.FileHandler):
                if h.baseFilename == _fsname:
                    break
        else:
            self.fail("Not logging to _fsname")


    def testAddServer(self):
        sd = self._createBlankSiteDefinition()

        from zope.configuration.action import Action

        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']
        self.assertEqual(server_info['port'], 8081)
        self.assertEqual(server_info['verbose'], 1)

    def testInitDB(self):
        sd = self._createBlankSiteDefinition()

        from zope.app.content.folder import IRootFolder
        from zope.app.publication.zopepublication import ZopePublication

        sd.useFileStorage(ContextStub(), file=_fsname)

        connection = sd._zodb.open()
        root = connection.root()
        app = root.get(ZopePublication.root_name, None)
        connection.close()
        self.assertEqual(app, None)

        sd._initDB()

        try:
            connection = sd._zodb.open()
            root = connection.root()
            app = root.get(ZopePublication.root_name, None)
            connection.close()
            self.failUnless(IRootFolder.isImplementedBy(app))
        finally:
            sd.close()

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

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