[Zope3-checkins] CVS: zopeproducts/demo/messageboard/step7/tests - test_messagemail.py:1.2 test_size.py:1.2

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Dec 14 19:20:13 EST 2003


Update of /cvs-repository/zopeproducts/demo/messageboard/step7/tests
In directory cvs.zope.org:/tmp/cvs-serv11937/tests

Modified Files:
	test_messagemail.py test_size.py 
Log Message:
Whee, the mailer tests were seriously broken. This was my first experience 
in dealing with the new way to store locations using ILocation. I must say
that I really like it. It is much cleaner this way.

Now step 7 should be fully finctional again.


=== zopeproducts/demo/messageboard/step7/tests/test_messagemail.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step7/tests/test_messagemail.py:1.1	Sat Jul 12 12:43:32 2003
+++ zopeproducts/demo/messageboard/step7/tests/test_messagemail.py	Sun Dec 14 19:20:13 2003
@@ -19,16 +19,19 @@
 
 from zope.app.interfaces.annotation import IAnnotations, IAttributeAnnotatable
 from zope.app.interfaces.event import ISubscriber
+from zope.app.interfaces.location import ILocation
 from zope.app.interfaces.mail import IMailService
-from zope.app.interfaces.traversing import IPhysicallyLocatable
+from zope.app.interfaces.traversing import \
+     IPhysicallyLocatable, IContainmentRoot
 from zopeproducts.messageboard.interfaces import IMessage, IMailSubscriptions
 
-from zope.interface import classImplements 
-from zope.component.adapter import provideAdapter
-from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.attributeannotations import AttributeAnnotations
-from zope.app.context import ContextWrapper
 from zope.app.event.objectevent import ObjectModifiedEvent
+from zope.app.location import LocationPhysicallyLocatable
+from zope.app import zapi
+from zope.component.service import defineService, serviceManager
+from zope.interface import implements, classImplements, directlyProvides
 
 from zopeproducts.messageboard.message import Message
 from zopeproducts.messageboard.message import \
@@ -37,12 +40,11 @@
 SubscriberKey = 'http://www.zope.org/messageboard#1.0/MailSubscriptions/emails'
 
 
-from zope.app.traversing.adapters import WrapperPhysicallyLocatable
-from zope.component.service import defineService, serviceManager
-from zope.interface import implements
-
 mail_result = [] 
 
+def provideAdapter(*args, **kw):
+    zapi.getService(None, 'Adapters').provideAdapter(*args, **kw)
+
 class MailServiceStub(object):
 
     implements(IMailService)
@@ -59,7 +61,7 @@
         # is usually set in the ZCML
         classImplements(Message, IAttributeAnnotatable)
         provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
+                       [AttributeAnnotations])
         self._sub = MailSubscriptions(Message())
 
     def test_Interface(self):
@@ -104,12 +106,14 @@
         PlacelessSetup.setUp(self)
         # This needs to be done, since the IAttributeAnnotable interface
         # is usually set in the ZCML
-        provideAdapter(None, IPhysicallyLocatable, WrapperPhysicallyLocatable)
+        provideAdapter(ILocation, IPhysicallyLocatable, 
+                       [LocationPhysicallyLocatable])
+
         classImplements(Message, IAttributeAnnotatable)
         provideAdapter(IMessage, IMailSubscriptions,
-                       MailSubscriptions)
+                       [MailSubscriptions])
         provideAdapter(IAttributeAnnotatable, IAnnotations,
-                       AttributeAnnotations)
+                       [AttributeAnnotations])
         defineService('Mail', IMailService)
         serviceManager.provideService('Mail', MailServiceStub())
 
@@ -118,25 +122,28 @@
 
     def test_getAllSubscribers(self):
         msg1 = Message()
+        directlyProvides(msg1, IContainmentRoot)
+        msg1.__name__ = 'msg1'
+        msg1.__parent__ = None
         msg1_sub = MailSubscriptions(msg1)
         msg1_sub.context.__annotations__[SubscriberKey] = ('foo at bar.com',)
-        wrapped_msg1 = ContextWrapper(msg1, object(), name='msg1')
         msg2 = Message()
         msg2_sub = MailSubscriptions(msg2)
         msg2_sub.context.__annotations__[SubscriberKey] = ('blah at bar.com',)
-        msg1.setObject('msg2', msg2)
-        wrapped_msg2 = ContextWrapper(msg2, wrapped_msg1, name="msg2")
+        msg1['msg2'] = msg2
         self.assertEqual(('blah at bar.com', 'foo at bar.com'),
-                         mailer.getAllSubscribers(wrapped_msg2))
+                         mailer.getAllSubscribers(msg2))
 
     def test_notify(self):
         msg = Message()
+        directlyProvides(msg, IContainmentRoot)
+        msg.__name__ = 'msg'
+        msg.__parent__ = None
         msg.title = 'Hello'
         msg.body = 'Hello World!'
         msg_sub = MailSubscriptions(msg)
         msg_sub.context.__annotations__[SubscriberKey] = ('foo at bar.com',)
-        wrapped_msg = ContextWrapper(msg, object(), name='msg')
-        event = ObjectModifiedEvent(wrapped_msg)
+        event = ObjectModifiedEvent(msg)
         mailer.notify(event)
         self.assertEqual('mailer at messageboard.org', mail_result[0][0])
         self.assertEqual(('foo at bar.com', ), mail_result[0][1])


=== zopeproducts/demo/messageboard/step7/tests/test_size.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step7/tests/test_size.py:1.1	Sat Jul 12 12:43:32 2003
+++ zopeproducts/demo/messageboard/step7/tests/test_size.py	Sun Dec 14 19:20:13 2003
@@ -17,12 +17,13 @@
 """
 import unittest
 from zope.app.interfaces.size import ISized
+from zope.app.tests.placelesssetup import PlacelessSetup
 from zopeproducts.messageboard.message import Message, MessageSized
 
 class Stub:
     pass
 
-class SizedTest(unittest.TestCase):
+class SizedTest(PlacelessSetup, unittest.TestCase):
 
     def test_interface(self):
         self.assert_(ISized.isImplementedBy(MessageSized(Message())))
@@ -30,9 +31,9 @@
     def test_sizeForSorting(self):
         size = MessageSized(Message())
         self.assertEqual(('item', 0), size.sizeForSorting())
-        size._message.setObject('msg1', Message()) 
+        size._message['msg1'] = Message()
         self.assertEqual(('item', 1), size.sizeForSorting())
-        size._message.setObject('att1', Stub()) 
+        size._message['att1'] = Stub()
         self.assertEqual(('item', 2), size.sizeForSorting())
 
     def test_sizeForDisplay(self):
@@ -41,22 +42,22 @@
                          str(size.sizeForDisplay()))
         self.assertEqual({'attach': '0', 'messages': '0'},
                          size.sizeForDisplay().mapping)
-        size._message.setObject('msg1', Message()) 
+        size._message['msg1'] = Message() 
         self.assertEqual('1 reply, ${attach} attachments',
                          size.sizeForDisplay())
         self.assertEqual({'attach': '0', 'messages': '1'},
                          size.sizeForDisplay().mapping)
-        size._message.setObject('msg2', Message()) 
+        size._message['msg2'] = Message() 
         self.assertEqual('${messages} replies, ${attach} attachments',
                          size.sizeForDisplay())
         self.assertEqual({'attach': '0', 'messages': '2'},
                          size.sizeForDisplay().mapping)
-        size._message.setObject('att1', Stub()) 
+        size._message['att1'] = Stub()
         self.assertEqual('${messages} replies, 1 attachment',
                          size.sizeForDisplay())
         self.assertEqual({'attach': '1', 'messages': '2'},
                          size.sizeForDisplay().mapping)
-        size._message.setObject('att2', Stub()) 
+        size._message['att2'] = Stub()
         self.assertEqual('${messages} replies, ${attach} attachments',
                          str(size.sizeForDisplay()))
         self.assertEqual({'attach': '2', 'messages': '2'},




More information about the Zope3-Checkins mailing list