[Zope3-checkins] CVS: zopeproducts/demo/messageboard/step11/tests -
test_fs.py:1.2 test_messagemail.py:1.2 test_size.py:1.2
test_xmlrpc.py:1.2
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Dec 15 11:01:33 EST 2003
Update of /cvs-repository/zopeproducts/demo/messageboard/step11/tests
In directory cvs.zope.org:/tmp/cvs-serv32347/tests
Modified Files:
test_fs.py test_messagemail.py test_size.py test_xmlrpc.py
Log Message:
Fixed XML-RPC recipe (step 11).
=== zopeproducts/demo/messageboard/step11/tests/test_fs.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step11/tests/test_fs.py:1.1 Fri Jul 18 07:56:03 2003
+++ zopeproducts/demo/messageboard/step11/tests/test_fs.py Mon Dec 15 11:01:32 2003
@@ -17,8 +17,8 @@
"""
import unittest
from zope.interface.verify import verifyObject
-from zope.component.adapter import provideAdapter
-from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app import zapi
from zopeproducts.messageboard.interfaces import \
IVirtualContentsFile, IPlainText, IMessage, IMessageBoard
@@ -31,6 +31,10 @@
VirtualContentsFile, ReadDirectory, MessageFactory
+def provideAdapter(*args, **kw):
+ zapi.getService(None, 'Adapters').provideAdapter(*args, **kw)
+
+
class VirtualContentsFileTestBase(PlacelessSetup):
def _makeFile(self):
@@ -74,7 +78,7 @@
return VirtualContentsFile(Message())
def _registerPlainTextAdapter(self):
- provideAdapter(IMessage, IPlainText, MessagePlainText)
+ provideAdapter(IMessage, IPlainText, [MessagePlainText])
def testMessageSpecifics(self):
file = self._makeFile()
@@ -94,7 +98,7 @@
return VirtualContentsFile(MessageBoard())
def _registerPlainTextAdapter(self):
- provideAdapter(IMessageBoard, IPlainText, MessageBoardPlainText)
+ provideAdapter(IMessageBoard, IPlainText, [MessageBoardPlainText])
def testMessageBoardSpecifics(self):
file = self._makeFile()
@@ -105,7 +109,7 @@
self.assertEqual(file.context.description, 'World 2')
-class ReadDirectoryTestBase:
+class ReadDirectoryTestBase(PlacelessSetup):
def _makeDirectoryObject(self):
raise NotImplemented
@@ -121,9 +125,9 @@
msg2 = Message()
msg2.title = 'Message 1'
msg2.description = 'This is Message 1.'
- msg1.setObject('msg11', msg11)
- base.setObject('msg1', msg1)
- base.setObject('msg2', msg2)
+ msg1['msg11'] = msg11
+ base['msg1'] = msg1
+ base['msg2'] = msg2
return ReadDirectory(base)
def testKeys(self):
=== zopeproducts/demo/messageboard/step11/tests/test_messagemail.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step11/tests/test_messagemail.py:1.1 Fri Jul 18 07:56:03 2003
+++ zopeproducts/demo/messageboard/step11/tests/test_messagemail.py Mon Dec 15 11:01:32 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/step11/tests/test_size.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step11/tests/test_size.py:1.1 Fri Jul 18 07:56:03 2003
+++ zopeproducts/demo/messageboard/step11/tests/test_size.py Mon Dec 15 11:01:32 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'},
=== zopeproducts/demo/messageboard/step11/tests/test_xmlrpc.py 1.1 => 1.2 ===
--- zopeproducts/demo/messageboard/step11/tests/test_xmlrpc.py:1.1 Fri Jul 18 07:56:03 2003
+++ zopeproducts/demo/messageboard/step11/tests/test_xmlrpc.py Mon Dec 15 11:01:32 2003
@@ -16,25 +16,16 @@
$Id$
"""
import unittest
-from zope.component.adapter import provideAdapter
-from zope.component.tests.placelesssetup import PlacelessSetup
+from zope.app.tests.placelesssetup import PlacelessSetup
from zope.publisher.xmlrpc import TestRequest
-from zope.app.interfaces.container import IContainer
-from zope.app.interfaces.context import IZopeContextWrapper
-from zope.app.container.zopecontainer import ZopeContainerDecorator
-from zope.app.context import ContextWrapper
-from zope.app.event.tests.placelesssetup import PlacelessSetup as EventSetup
+from zope.app import zapi
from zopeproducts.messageboard.message import Message
from zopeproducts.messageboard.messageboard import MessageBoard
from zopeproducts.messageboard.xmlrpc import MessageBoardMethods, MessageMethods
+def provideAdapter(*args, **kw):
+ zapi.getService(None, 'Adapters').provideAdapter(*args, **kw)
-
-class MessageContainerTest(PlacelessSetup, EventSetup):
-
- def setUp(self):
- PlacelessSetup.setUp(self)
- EventSetup.setUp(self)
- provideAdapter(IContainer, IZopeContextWrapper, ZopeContainerDecorator)
+class MessageContainerTest(PlacelessSetup):
def _makeMethodObject(self):
return NotImplemented
@@ -47,8 +38,8 @@
msg2 = Message()
msg2.title = 'Message 1'
msg2.description = 'This is Message 1.'
- methods.context.setObject('msg1', msg1)
- methods.context.setObject('msg2', msg2)
+ methods.context['msg1'] = msg1
+ methods.context['msg2'] = msg2
return methods
def test_getMessageNames(self):
@@ -71,8 +62,7 @@
class MessageBoardMethodsTest(MessageContainerTest, unittest.TestCase):
def _makeMethodObject(self):
- return MessageBoardMethods(ContextWrapper(MessageBoard(), None),
- TestRequest())
+ return MessageBoardMethods(MessageBoard(), TestRequest())
def test_description(self):
methods = self._makeTree()
@@ -84,8 +74,7 @@
class MessageMethodsTest(MessageContainerTest, unittest.TestCase):
def _makeMethodObject(self):
- return MessageMethods(ContextWrapper(Message(), None),
- TestRequest())
+ return MessageMethods(Message(), TestRequest())
def test_title(self):
methods = self._makeTree()
More information about the Zope3-Checkins
mailing list