[Zope3-checkins] CVS: Zope3/src/zope/app/fssync/tests - test_fsdirective.py:1.1 test_fsregistry.py:1.1 testFSDirective.py:NONE testFSRegistry.py:NONE

Guido van Rossum guido@python.org
Thu, 8 May 2003 12:56:13 -0400


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

Added Files:
	test_fsdirective.py test_fsregistry.py 
Removed Files:
	testFSDirective.py testFSRegistry.py 
Log Message:
Rename test modules to lowercase names.

=== Added File Zope3/src/zope/app/fssync/tests/test_fsdirective.py ===
##############################################################################
#
# Copyright) 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.
#
##############################################################################
"""Test FSRegistry File-system synchronization services

$Id: test_fsdirective.py,v 1.1 2003/05/08 16:56:12 gvanrossum Exp $
"""

from cStringIO import StringIO
from unittest import TestCase, TestSuite, main, makeSuite

from zope.configuration.xmlconfig import testxmlconfig as xmlconfig, XMLConfig
from zope.testing.cleanup import CleanUp # Base class w registry cleanup
from zope.app.fssync.fsregistry import getSynchronizer
from zope.app.interfaces.fssync \
     import IGlobalFSSyncService, IObjectFile, IObjectDirectory
from zope.interface.verify import verifyObject
from zope.exceptions import DuplicationError, NotFoundError
from zope.configuration.exceptions import ConfigurationError
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component.service import UndefinedService
from zope.app.fssync.tests.sampleclass \
     import C1, C2, CDirAdapter, CFileAdapter, CDefaultAdapter

import zope.app.fssync

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

class Test(PlacelessSetup, TestCase):
    """
    """    
    def setUp(self):
        PlacelessSetup.setUp(self)
        XMLConfig('meta.zcml', zope.app.fssync)()

    def testFSDirective(self):
        """Test for Synchrozier not found and Registering the
        adapter for a class.
        """
        from zope.app.fssync.tests.sampleclass import C1
    
        # Register the adapter for the class
        self.assertRaises(NotFoundError, getSynchronizer, C2())

        xmlconfig(StringIO(template % (
             """
             <fssync:adapter
             class_="zope.app.fssync.tests.sampleclass.C2"
             factory="zope.app.fssync.tests.sampleclass.CDirAdapter"
             />
             """
             )))
        self.assertEqual(getSynchronizer(C2()).__class__, CDirAdapter)

    def testFSDirectiveDefaultAdapter(self):
        """Test for getting default adapter for not registered Classes"""
        xmlconfig(StringIO(template % (
              """
              <fssync:adapter
              factory = "zope.app.fssync.tests.sampleclass.CDefaultAdapter"
              />
              """
              )))
        self.assertEqual(getSynchronizer(C2()).__class__, CDefaultAdapter)
        
    def testFSDirectiveDuplicate(self):
        """Duplication test"""
        xmlconfig(StringIO(template % (
             """
             <fssync:adapter
             class_="zope.app.fssync.tests.sampleclass.C1"
             factory="zope.app.fssync.tests.sampleclass.CDirAdapter"
             />
             """
             )))
        
        self.assertRaises(DuplicationError, xmlconfig, StringIO(template % (
             """
             <fssync:adapter
             class_="zope.app.fssync.tests.sampleclass.C1"
             factory="zope.app.fssync.tests.sampleclass.CFileAdapter"
             />
             """
             )))

def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')


=== Added File Zope3/src/zope/app/fssync/tests/test_fsregistry.py ===
##############################################################################
#
# Copyright) 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.
#
##############################################################################
"""Test FSRegistry File-system synchronization services

$Id: test_fsregistry.py,v 1.1 2003/05/08 16:56:12 gvanrossum Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from zope.testing.cleanup import CleanUp # Base class w registry cleanup
from zope.app.interfaces.fssync \
     import IGlobalFSSyncService, IObjectFile, IObjectDirectory
from zope.interface.verify import verifyObject
from zope.exceptions import DuplicationError, NotFoundError
from zope.app.fssync.tests.sampleclass \
     import C1, C2, CDirAdapter, CFileAdapter, CDefaultAdapter
from zope.app.fssync.fsregistry \
     import getSynchronizer, provideSynchronizer, fsRegistry

class Test(CleanUp, TestCase):
    """Test Interface for FSRegistry Instance.
    """

    def testInterfaceVerification(self):        
        verifyObject(IGlobalFSSyncService, fsRegistry)

    def testFSRegistry(self):
        """ Test Class and Factory registration and getSynchronizer to get
           appropriate factory for that class.
        """
	self.assertRaises(NotFoundError, getSynchronizer, C1())

        provideSynchronizer(C1, CFileAdapter)
        cl = C1()
        fac = getSynchronizer(cl)
        self.assertEqual(fac.__class__, CFileAdapter)
        self.assertEqual(fac.getBody(), C1.__doc__)
        
        provideSynchronizer(C2, CDirAdapter)
        fac = getSynchronizer(C2())
        self.assertEqual(fac.__class__, CDirAdapter)
        self.assertEqual(fac.contents(), [])

    def testFSRegitryDefaultFactory(self):
        """Test for default Factory
        """
        provideSynchronizer(None, CDefaultAdapter)
        fac = getSynchronizer(C1())
        self.assertEqual(fac.__class__, CDefaultAdapter)

        fac = getSynchronizer(C2())
        self.assertEqual(fac.__class__, CDefaultAdapter)

    def testFSRegDuplication(self):
        """Test for duplication in registring the same class in
        to the Registry.
        """
        provideSynchronizer(C2, CFileAdapter)       
        #Try to change the adapter for same class should
        #throw a duplication error
        self.assertRaises(DuplicationError,
                          provideSynchronizer, C2, CDirAdapter)

def test_suite():
    return TestSuite((makeSuite(Test),))

if __name__=='__main__':
    main(defaultTest='test_suite')

=== Removed File Zope3/src/zope/app/fssync/tests/testFSDirective.py ===

=== Removed File Zope3/src/zope/app/fssync/tests/testFSRegistry.py ===