[Checkins] SVN: zope.dublincore/trunk/ Removed use of zope.app.component in testing.
Tres Seaver
tseaver at palladion.com
Mon Jun 29 16:58:01 EDT 2009
Log message for revision 101331:
Removed use of zope.app.component in testing.
Changed:
U zope.dublincore/trunk/CHANGES.txt
U zope.dublincore/trunk/setup.py
U zope.dublincore/trunk/src/zope/dublincore/tests/test_creatorannotator.py
-=-
Modified: zope.dublincore/trunk/CHANGES.txt
===================================================================
--- zope.dublincore/trunk/CHANGES.txt 2009-06-29 17:17:50 UTC (rev 101330)
+++ zope.dublincore/trunk/CHANGES.txt 2009-06-29 20:58:01 UTC (rev 101331)
@@ -4,6 +4,8 @@
3.4.3 (unreleased)
------------------
+- Removed use of zope.app.component in testing.
+
- Include browser configuration only if zope.app.publisher is installed.
3.4.2 (2009-01-31)
Modified: zope.dublincore/trunk/setup.py
===================================================================
--- zope.dublincore/trunk/setup.py 2009-06-29 17:17:50 UTC (rev 101330)
+++ zope.dublincore/trunk/setup.py 2009-06-29 20:58:01 UTC (rev 101331)
@@ -37,10 +37,10 @@
include_package_data=True,
extras_require=dict(
test=[
- 'zope.app.component',
'zope.testing',
'zope.security',
- 'zope.app.testing']
+ 'zope.app.testing',
+ ]
),
install_requires = ['setuptools',
'zope.annotation',
Modified: zope.dublincore/trunk/src/zope/dublincore/tests/test_creatorannotator.py
===================================================================
--- zope.dublincore/trunk/src/zope/dublincore/tests/test_creatorannotator.py 2009-06-29 17:17:50 UTC (rev 101330)
+++ zope.dublincore/trunk/src/zope/dublincore/tests/test_creatorannotator.py 2009-06-29 20:58:01 UTC (rev 101331)
@@ -15,129 +15,119 @@
$Id$
"""
-from unittest import TestCase, TestSuite, main, makeSuite
-from zope.app.component.testing import PlacefulSetup
-from zope.testing.cleanup import CleanUp
+import unittest
-from zope.interface import Interface, implements
-import zope.component
+class CreatorAnnotatorTests(unittest.TestCase):
-from zope.dublincore.creatorannotator import CreatorAnnotator
-from zope.dublincore.interfaces import IZopeDublinCore
-from zope.security.interfaces import IPrincipal
-from zope.security.management import newInteraction, endInteraction
+ def setUp(self):
+ from zope.testing.cleanup import cleanUp
+ cleanUp()
+ self._makeInterface()
+ self._registerAdapter()
-class IDummyContent(Interface):
- pass
+ def tearDown(self):
+ from zope.testing.cleanup import cleanUp
+ from zope.security.management import endInteraction
+ endInteraction()
+ cleanUp()
-class DummyEvent(object):
- pass
+ def _callFUT(self, event):
+ from zope.dublincore.creatorannotator import CreatorAnnotator
+ return CreatorAnnotator(event)
-class DummyDCAdapter(object):
+ def _makeInterface(self):
+ from zope.interface import Interface
- __used_for__ = IDummyContent
- implements(IZopeDublinCore)
+ class IDummyContent(Interface):
+ pass
- def _getcreator(self):
- return self.context.creators
+ self._iface = IDummyContent
- def _setcreator(self, value):
- self.context.creators = value
- creators = property(_getcreator, _setcreator, None, "Adapted Creators")
+ def _registerAdapter(self):
+ from zope.component import provideAdapter
+ from zope.dublincore.interfaces import IZopeDublinCore
+ provideAdapter(DummyDCAdapter, (self._iface, ), IZopeDublinCore)
- def __init__(self, context):
- self.context = context
- self.creators = context.creators
+ def _makeContextAndEvent(self):
+ from zope.interface import implements
-class DummyDublinCore(object):
+ class DummyDublinCore(object):
+ implements(self._iface)
+ creators = ()
- implements(IDummyContent)
+ class DummyEvent(object):
+ def __init__(self, object):
+ self.object = object
- creators = ()
+ context = DummyDublinCore()
+ event = DummyEvent(context)
+ return context, event
+ def _setPrincipal(self, id):
+ from zope.security.management import newInteraction
+ class DummyPrincipal(object):
+ title = 'TITLE'
+ description = 'DESCRIPTION'
+ def __init__(self, id):
+ self.id = id
+ if id is None:
+ newInteraction(DummyRequest(None))
+ else:
+ newInteraction(DummyRequest(DummyPrincipal(id)))
-class DummyPrincipal(object):
- implements(IPrincipal)
+ def test_w_no_request(self):
+ context, event = self._makeContextAndEvent()
+ self._callFUT(event)
+ self.assertEqual(context.creators, ())
- def __init__(self, id, title, description):
- self.id = id
- self.title = title
- self.description = description
+ def test_w_request_no_existing_creators(self):
+ context, event = self._makeContextAndEvent()
+ self._setPrincipal('phred')
+ self._callFUT(event)
+ self.assertEqual(context.creators, ('phred',))
+ def test_w_request_w_existing_creator_nomatch(self):
+ context, event = self._makeContextAndEvent()
+ context.creators = ('bharney',)
+ self._setPrincipal('phred')
+ self._callFUT(event)
+ self.assertEqual(context.creators, ('bharney', 'phred',))
-class DummyRequest(object):
+ def test_w_request_w_existing_creator_nomatch(self):
+ context, event = self._makeContextAndEvent()
+ context.creators = ('bharney', 'phred')
+ self._setPrincipal('phred')
+ self._callFUT(event)
+ self.assertEqual(context.creators, ('bharney', 'phred',))
- def __init__(self, principal):
- self.principal = principal
- self.interaction = None
+ def test_w_request_no_principal(self):
+ context, event = self._makeContextAndEvent()
+ context.creators = ('bharney', 'phred')
+ self._setPrincipal(None)
+ self._callFUT(event)
+ self.assertEqual(context.creators, ('bharney', 'phred',))
+class DummyDCAdapter(object):
-class Test(PlacefulSetup, TestCase, CleanUp):
+ def _getcreator(self):
+ return self.context.creators
+ def _setcreator(self, value):
+ self.context.creators = value
+ creators = property(_getcreator, _setcreator, None, "Adapted Creators")
- def setUp(self):
- PlacefulSetup.setUp(self)
- gsm = zope.component.getGlobalSiteManager()
- gsm.registerAdapter(DummyDCAdapter, (IDummyContent, ), IZopeDublinCore)
+ def __init__(self, context):
+ self.context = context
- def tearDown(self):
- PlacefulSetup.tearDown(self)
- def test_creatorannotation(self):
- # Create stub event and DC object
- event = DummyEvent()
- data = DummyDublinCore()
- event.object = data
+class DummyRequest(object):
- good_author = DummyPrincipal('goodauthor', 'the good author',
- 'this is a very good author')
+ def __init__(self, principal):
+ self.principal = principal
+ self.interaction = None
- bad_author = DummyPrincipal('badauthor', 'the bad author',
- 'this is a very bad author')
- # Check what happens if no user is there
- CreatorAnnotator(event)
- self.assertEqual(data.creators,())
- endInteraction()
-
- # Let the bad edit it first
- newInteraction(DummyRequest(bad_author))
- CreatorAnnotator(event)
-
- self.failIf(len(data.creators) != 1)
- self.failUnless(bad_author.id in data.creators)
- endInteraction()
-
- # Now let the good edit it
- newInteraction(DummyRequest(good_author))
- CreatorAnnotator(event)
-
- self.failIf(len(data.creators) != 2)
- self.failUnless(good_author.id in data.creators)
- self.failUnless(bad_author.id in data.creators)
- endInteraction()
-
- # Let the bad edit it again
- newInteraction(DummyRequest(bad_author))
- CreatorAnnotator(event)
-
- # Check that the bad author hasn't been added twice.
- self.failIf(len(data.creators) != 2)
- self.failUnless(good_author.id in data.creators)
- self.failUnless(bad_author.id in data.creators)
- endInteraction()
-
- # Now, let's check if the auto-subscriber will work with None
- # as principal (can happen sometimes in custom code).
- newInteraction(DummyRequest(None))
- CreatorAnnotator(event)
- self.failIf(len(data.creators) != 2)
- endInteraction()
-
def test_suite():
- return TestSuite((
- makeSuite(Test),
+ return unittest.TestSuite((
+ unittest.makeSuite(CreatorAnnotatorTests),
))
-
-if __name__=='__main__':
- main(defaultTest='test_suite')
More information about the Checkins
mailing list