[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/FSSync/tests - SampleClass.py:1.1.2.1 __init__.py:1.1.2.1 testFSDirective.py:1.1.2.1 testFSRegistry.py:1.1.2.1
Naveen P
pnaveen@zeomega.com
Tue, 15 Oct 2002 09:57:58 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/FSSync/tests
In directory cvs.zope.org:/tmp/cvs-serv10773
Added Files:
Tag: FileSystemSync-branch
SampleClass.py __init__.py testFSDirective.py
testFSRegistry.py
Log Message:
Test files added
=== Added File Zope3/lib/python/Zope/App/FSSync/tests/SampleClass.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 SampleClass for testing File-system synchronization services
$Id: SampleClass.py,v 1.1.2.1 2002/10/15 13:57:58 pnaveen Exp $
"""
from Zope.App.FSSync.IObjectDirectory import IObjectDirectory
from Zope.App.FSSync.IObjectFile import IObjectFile
class C1: "C1 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
=== Added File Zope3/lib/python/Zope/App/FSSync/tests/__init__.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
=== Added File Zope3/lib/python/Zope/App/FSSync/tests/testFSDirective.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: testFSDirective.py,v 1.1.2.1 2002/10/15 13:57:58 pnaveen 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 querySynchronizer
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
from Zope.Configuration.Exceptions import ConfigurationError
from Zope.App.tests.PlacelessSetup import PlacelessSetup
from Zope.ComponentArchitecture.GlobalServiceManager import UndefinedService
from Zope.App.FSSync.tests.SampleClass import C1, C2, CDirAdapter, CFileAdapter
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):
from Zope.App.FSSync.tests.SampleClass import C1
# Register the adapter for the class
self.assertEqual(querySynchronizer(C2()), None)
xmlconfig(StringIO(template % (
"""
<FSSync:adapter
class_="Zope.App.FSSync.tests.SampleClass.C2"
factory="Zope.App.FSSync.tests.SampleClass.CDirAdapter"
/>
"""
)))
self.assertEqual(querySynchronizer(C2()).__class__, CDirAdapter)
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/lib/python/Zope/App/FSSync/tests/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/15 13:57:58 pnaveen Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
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
from Zope.App.FSSync.tests.SampleClass import C1, C2, CDirAdapter, CFileAdapter
from Zope.App.FSSync.FSRegistry import querySynchronizer, provideSynchronizer, fsRegistry
class Test(CleanUp, TestCase):
"""
"""
"""Test Interface for FSRegistry Instance.
"""
def testInterfaceVerification(self):
verifyObject(IGlobalFSSyncService, fsRegistry)
"""Test Class and Factory registration and QuerySynchronizer to get
appropriate factory for that class.
"""
def testFSRegistration(self):
fac = querySynchronizer(C1())
self.assertEqual(fac, None)
provideSynchronizer(C1, CFileAdapter)
fac = querySynchronizer(C2())
self.assertEqual(fac, None)
provideSynchronizer(C2, CDirAdapter)
cls=C1()
fac = querySynchronizer(cls)
self.assertEqual(fac.__class__, CFileAdapter)
self.assertEqual(fac.getBody(), C1.__doc__)
fac = querySynchronizer(C2())
self.assertEqual(fac.__class__, CDirAdapter)
self.assertEqual(fac.contents(), [])
"""Test for duplication in registring the same class in to the Registry.
"""
def testFSRegDuplication(self):
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')