[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests - testAdding.py:1.3.2.1 testContents.py:1.5.2.1

Jim Fulton jim@zope.com
Fri, 4 Oct 2002 13:30:38 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv10951/lib/python/Zope/App/OFS/Container/Views/Browser/tests

Modified Files:
      Tag: ZopeDublinCore-branch
	testAdding.py testContents.py 
Log Message:
Commiting branch prior to merge

=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testAdding.py 1.3 => 1.3.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testAdding.py:1.3	Wed Oct  2 17:35:47 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testAdding.py	Fri Oct  4 13:30:07 2002
@@ -20,13 +20,15 @@
 
 from Zope.App.OFS.Container.Views.Browser.Adding import Adding
 from Zope.App.OFS.Container.IAdding import IAdding
-from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
 from Zope.ComponentArchitecture.GlobalViewService import provideView
 from Zope.Proxy.ContextWrapper \
      import getWrapperObject, getWrapperContainer, getWrapperData
 from Zope.Publisher.Browser.BrowserRequest import TestRequest
 from Zope.Publisher.Browser.BrowserView import BrowserView
 from Zope.Publisher.Browser.IBrowserPresentation import IBrowserPresentation
+from Zope.Event.tests.PlacelessSetup import getEvents
+from Zope.Event.IObjectEvent import IObjectAddedEvent, IObjectModifiedEvent
 
 class Container:
     def __init__(self):
@@ -56,8 +58,29 @@
         view = adding.publishTraverse(request, 'Thing=foo') 
         self.assertEqual(view.action(), 'been there, done that')
         self.assertEqual(adding.contentName, 'foo')
+
+        # Make sure we don't have any events yet:
+        self.failIf(getEvents(IObjectModifiedEvent))
+        self.failIf(getEvents(IObjectAddedEvent))
+
         o = Container() # any old instance will do
         result = adding.add(o)
+
+        # Make sure the right events were generated:
+        self.failUnless(
+            getEvents(IObjectAddedEvent,
+                      filter =
+                      lambda event:
+                      event.object == o)
+            )
+        self.failUnless(
+            getEvents(IObjectModifiedEvent,
+                      filter =
+                      lambda event:
+                      event.object == container)
+            )
+
+        # Check the state of the container and result
         self.assertEqual(container["foo"], o)
         self.assertEqual(getWrapperContainer(result), container)
         self.assertEqual(getWrapperObject(result), o)


=== Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testContents.py 1.5 => 1.5.2.1 ===
--- Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testContents.py:1.5	Wed Jul 17 12:54:17 2002
+++ Zope3/lib/python/Zope/App/OFS/Container/Views/Browser/tests/testContents.py	Fri Oct  4 13:30:07 2002
@@ -18,13 +18,17 @@
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from Zope.App.tests.PlacelessSetup import PlacelessSetup
 from Zope.ComponentArchitecture.GlobalAdapterService import provideAdapter
 
 from Zope.I18n.IUserPreferredCharsets import IUserPreferredCharsets
 
 from Zope.Publisher.HTTP.HTTPRequest import IHTTPRequest
 from Zope.Publisher.HTTP.HTTPCharsets import HTTPCharsets
+from Zope.Event.tests.PlacelessSetup import getEvents
+from Zope.Event.IObjectEvent import IObjectRemovedEvent, IObjectModifiedEvent
+from Interface import Interface
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
 
 
 class BaseTestContentsBrowserView(PlacelessSetup):
@@ -61,24 +65,71 @@
         objects = map( lambda x: x['object'], info_list )
         self.assert_( subcontainer in objects )
 
-        titles = map( lambda x: x['title'], info_list )
-        self.assert_( 'subcontainer' in titles )
-
         urls = map( lambda x: x['url'], info_list )
         self.assert_( 'subcontainer' in urls )
 
         self.failIf( filter( None, map( lambda x: x['icon'], info_list ) ) )
 
+    def testInfoWDublinCore(self):
+        container = self._TestView__newContext()
+        document = Document()
+        container.setObject( 'document', document )
+
+        from datetime import datetime
+        from Zope.App.DublinCore.IZopeDublinCore import IZopeDublinCore
+
+        class FauxDCAdapter:
+            __implements__ = IZopeDublinCore
+            
+            def __init__(self, context):
+                pass
+            title = 'faux title'
+            created = datetime(2001, 1, 1, 1, 1, 1)
+            modified = datetime(2002, 2, 2, 2, 2, 2)
+
+        from Zope.ComponentArchitecture.GlobalAdapterService \
+             import provideAdapter
+        provideAdapter(IDocument, IZopeDublinCore, FauxDCAdapter)
+        
+        fc = self._TestView__newView( container )
+        info = fc.listContentInfo()[0]
+
+        self.assertEqual(info['id'], 'document')
+        self.assertEqual(info['url'], 'document')
+        self.assertEqual(info['object'], document)
+        self.assertEqual(info['title'], 'faux title')
+        self.assertEqual(info['created'], FauxDCAdapter.created)
+        self.assertEqual(info['modified'], FauxDCAdapter.modified)
+
     def testRemove( self ):
         container = self._TestView__newContext()
         subcontainer = self._TestView__newContext()
-        container.setObject( 'subcontainer', subcontainer )
+        container.setObject('subcontainer', subcontainer)
         document = Document()
-        container.setObject( 'document', document )
-        container.setObject( 'document2', Document() )
+        container.setObject('document', document)
+        document2 = Document()
+        container.setObject('document2', document2)
 
         fc = self._TestView__newView( container )
-        fc.remove( name='document2' )
+
+        self.failIf(getEvents(IObjectModifiedEvent))
+        self.failIf(getEvents(IObjectRemovedEvent))
+
+        fc.removeObjects(['document2'])
+
+        self.failUnless(
+            getEvents(IObjectRemovedEvent,
+                      filter =
+                      lambda event:
+                      removeAllProxies(event.object) == document2)
+            )
+        self.failUnless(
+            getEvents(IObjectModifiedEvent,
+                      filter =
+                      lambda event:
+                      removeAllProxies(event.object) == container)
+            )
+        
         info_list = fc.listContentInfo()
 
         self.assertEquals( len( info_list ), 2 )
@@ -89,19 +140,15 @@
         objects = map( lambda x: x['object'], info_list )
         self.assert_( subcontainer in objects )
 
-        titles = map( lambda x: x['title'], info_list )
-        self.assert_( 'subcontainer' in titles )
-
         urls = map( lambda x: x['url'], info_list )
         self.assert_( 'subcontainer' in urls )
 
-        self.assertRaises( KeyError, fc.remove, 'document3' )
-
-        fc.remove( 'document3', 1 )
 
+class IDocument(Interface):
+    pass
 
 class Document:
-    pass
+    __implements__ = IDocument
 
 
 class Test(BaseTestContentsBrowserView, TestCase):