[Zope3-checkins] CVS: Zope3/src/zope/app/fssync/tests - __init__.py:1.2 sampleclass.py:1.2 testFSDirective.py:1.2 testFSRegistry.py:1.2
Guido van Rossum
guido@python.org
Mon, 5 May 2003 14:01:34 -0400
Update of /cvs-repository/Zope3/src/zope/app/fssync/tests
In directory cvs.zope.org:/tmp/cvs-serv2527/src/zope/app/fssync/tests
Added Files:
__init__.py sampleclass.py testFSDirective.py
testFSRegistry.py
Log Message:
Merge fssync stuff back to trunk. A few things actually work (I
successfully did a checkout of some files and diffed them; though
commit doesn't seem to work yet), and you know how I love long-living
branches....
=== Zope3/src/zope/app/fssync/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null Mon May 5 14:01:34 2003
+++ Zope3/src/zope/app/fssync/tests/__init__.py Mon May 5 14:01:02 2003
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.
=== Zope3/src/zope/app/fssync/tests/sampleclass.py 1.1 => 1.2 ===
--- /dev/null Mon May 5 14:01:34 2003
+++ Zope3/src/zope/app/fssync/tests/sampleclass.py Mon May 5 14:01:02 2003
@@ -0,0 +1,91 @@
+##############################################################################
+#
+# 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$
+"""
+
+from zope.app.interfaces.fssync import IObjectDirectory, IObjectFile
+
+class C1: "C1 Doc"
+class C2: "C2 Doc"
+
+
+class CDefaultAdapter:
+ """Default File-system representation for object
+ """
+ __implements__ = IObjectFile
+
+ def __init__(self, object):
+ self.context = object
+
+ def extra(self):
+ pass
+
+ def typeIdentifier(self):
+ return "Default"
+
+ def factory(self):
+ return "Default Factory"
+
+ def getBody(self):
+ return self.context.__doc__
+
+ def setBody(self):
+ pass
+
+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
=== Zope3/src/zope/app/fssync/tests/testFSDirective.py 1.1 => 1.2 ===
--- /dev/null Mon May 5 14:01:34 2003
+++ Zope3/src/zope/app/fssync/tests/testFSDirective.py Mon May 5 14:01:02 2003
@@ -0,0 +1,106 @@
+##############################################################################
+#
+# 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$
+"""
+
+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')
=== Zope3/src/zope/app/fssync/tests/testFSRegistry.py 1.1 => 1.2 ===
--- /dev/null Mon May 5 14:01:34 2003
+++ Zope3/src/zope/app/fssync/tests/testFSRegistry.py Mon May 5 14:01:02 2003
@@ -0,0 +1,79 @@
+##############################################################################
+#
+# 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$
+"""
+
+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')