[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/FSSync/test - testFSRegistry.py:1.1.2.1

Naveen P pnaveen@zeomega.com
Fri, 11 Oct 2002 08:30:50 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/FSSync/test
In directory cvs.zope.org:/tmp/cvs-serv32465/test

Added Files:
      Tag: FileSystemSync-branch
	testFSRegistry.py 
Log Message:
FSRegistry Created by naveen


=== Added File Zope3/lib/python/Zope/App/FSSync/test/testFSRegistry.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: testFSRegistry.py,v 1.1.2.1 2002/10/11 12:30:50 pnaveen Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.App.FSSync.FSRegistry import FSRegistry
from Zope.App.FSSync.IGlobalFSSyncService import IGlobalFSSyncService
from Zope.App.FSSync.IObjectFile import IObjectFile
from Zope.App.FSSync.IObjectDirectory import IObjectDirectory
from Interface.Verify import verifyObject
from Zope.Exceptions import DuplicationError

class C: "C Doc"
class C2: "C2 Doc"

class CDirAdapter:
    """Directory Adapter
    """

    __implements__ = IObjectDirectory
    	
    def __init__(self, object):
	self.context = object
	
    def extra(self):
        pass
	
    def typeIdentifier(self):
        return "Folder"
	
    def factory(self):
	return "Folder Factory"
	
    def contents(self):
    	return []

class CFileAdapter:
    """File Adapter
    """

    __implements__ = IObjectFile

    def __init__(self, object):
	self.context = object
	
    def extra(self):    
        pass
	
    def typeIdentifier(self):
        return "File"
	
    def factory(self):
	return "File Factory"
	
    def getBody(self):
        return self.context.__doc__
	
    def setBody(self):
        pass

class Test(CleanUp, TestCase):

    def testInterfaceVerification(self):
        reg = FSRegistry()
        verifyObject(IGlobalFSSyncService, reg)

    def testFSRegistration(self):
        reg = FSRegistry()
        fac = reg.querySynchronizer(C())
        self.assertEqual(fac, None)

        reg.provideSynchronizer(C, CFileAdapter)
        fac = reg.querySynchronizer(C2())
        self.assertEqual(fac, None)
        reg.provideSynchronizer(C2, CDirAdapter)

        fac = reg.querySynchronizer(C())
        self.assertEqual(fac.__class__, CFileAdapter)
        self.assertEqual(fac.getBody(), C.__doc__)
        
        fac = reg.querySynchronizer(C2())
        self.assertEqual(fac.__class__, CDirAdapter)
        self.assertEqual(fac.contents(), [])

    def testFSRegDuplication(self):
        reg = FSRegistry()
        reg.provideSynchronizer(C2, CFileAdapter)       
        # try to change the adapter for same class should throw a duplication error
	self.assertRaises(DuplicationError, reg.provideSynchronizer, C2, CDirAdapter)
	
def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

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