[Zope3-checkins] CVS: Products3/z3checkins/tests - __init__.py:1.2 test_message.py:1.12

Marius Gedminas mgedmin@codeworks.lt
Fri, 1 Aug 2003 05:43:28 -0400


Update of /cvs-repository/Products3/z3checkins/tests
In directory cvs.zope.org:/tmp/cvs-serv820/tests

Modified Files:
	__init__.py test_message.py 
Log Message:
It is now possible to add regular email messages to z3checkins.  Unfortunately
this breaks backwards compatibility with old pickles.



=== Products3/z3checkins/tests/__init__.py 1.1.1.1 => 1.2 ===
--- Products3/z3checkins/tests/__init__.py:1.1.1.1	Thu Apr  3 03:20:00 2003
+++ Products3/z3checkins/tests/__init__.py	Fri Aug  1 05:43:23 2003
@@ -1,3 +1,5 @@
 """
-Unit tests for z3-checkins.
+Unit tests for z3checkins.
+
+$Id$
 """


=== Products3/z3checkins/tests/test_message.py 1.11 => 1.12 ===
--- Products3/z3checkins/tests/test_message.py:1.11	Thu Jun  5 08:10:32 2003
+++ Products3/z3checkins/tests/test_message.py	Fri Aug  1 05:43:23 2003
@@ -1,6 +1,8 @@
 #!/usr/bin/python
 """
 Unit tests for message.py
+
+$Id$
 """
 
 import unittest
@@ -13,15 +15,16 @@
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.component import getService
 from zope.component.view import provideView
-from zope.interface import Interface
+from zope.interface import Interface, implements
 from zope.interface.verify import verifyObject
 from zope.context import getWrapperContext, getWrapperData
 from zope.app.context import ContextWrapper
 
+from zopeproducts.z3checkins.interfaces import IMessage
 from zopeproducts.z3checkins.interfaces import ICheckinMessage
-from zopeproducts.z3checkins.interfaces import ICheckinMessageParser
-from zopeproducts.z3checkins.interfaces import ICheckinMessageArchive
-from zopeproducts.z3checkins.interfaces import ICheckinBookmark
+from zopeproducts.z3checkins.interfaces import IBookmark
+from zopeproducts.z3checkins.interfaces import IMessageParser
+from zopeproducts.z3checkins.interfaces import IMessageArchive
 
 
 class TestFixedTimezone(unittest.TestCase):
@@ -72,69 +75,39 @@
 
 class TestCheckinMessage(unittest.TestCase):
 
+    def test_find_body_start(self):
+        from zopeproducts.z3checkins.message import find_body_start
+        self.assertEquals(find_body_start("Foo: X\nBar: Y\n  Z\n\nQQQ"), 19)
+        self.assertEquals(find_body_start("Foo: X\r\nBar: Y\r\n  Z\r\n\r\nQQQ"),
+                          23)
+        self.assertEquals(find_body_start("Foo: X\n\nQQQ\n\nWWW"), 8)
+        self.assertEquals(find_body_start("Foo: X\n\n\nQQQ\n\nWWW"), 8)
+        self.assertEquals(find_body_start("Foo: X\n\nQQQ\r\n\r\nWWW"), 8)
+        self.assertEquals(find_body_start("Foo: X\r\n\r\nQQQ\n\nWWW"), 10)
+        self.assertEquals(find_body_start("Foo: X\n\n"), 8)
+        self.assertEquals(find_body_start("\r\n\r\n"), 4)
+        self.assertEquals(find_body_start("xyzzy"), 5)
+
     def test_interface(self):
+        from zopeproducts.z3checkins.message import Message
         from zopeproducts.z3checkins.message import CheckinMessage
+        verifyObject(IMessage, Message())
         verifyObject(ICheckinMessage, CheckinMessage())
 
+    def test_body(self):
+        from zopeproducts.z3checkins.message import Message
+        m = Message(full_text="Subject: foo\n\nBody text\n")
+        self.assertEquals(m.body, "Body text\n")
+
     def test_equality(self):
-        from zopeproducts.z3checkins.message import CheckinMessage
-        a = CheckinMessage(message_id="abc")
-        b = CheckinMessage(message_id="abc")
-        c = CheckinMessage(message_id="xyz")
+        from zopeproducts.z3checkins.message import Message
+        a = Message(message_id="abc")
+        b = Message(message_id="abc")
+        c = Message(message_id="xyz")
         self.assertEquals(a, b)
         self.assertNotEquals(a, c)
         self.assertNotEquals(b, c)
 
-    def test_setstate(self):
-        from zopeproducts.z3checkins.message import CheckinMessage
-        a = CheckinMessage(message_id='1', author='2', author_name='3',
-                           author_email='4', subject='5', date='6',
-                           directory='7', log_message='8', body='9',
-                           branch='10')
-        state = a.__getstate__()
-        b = CheckinMessage()
-        b.__setstate__(state)
-        self.assertEquals(a.__dict__, b.__dict__)
-
-    def test_setstate_branch1(self):
-        from zopeproducts.z3checkins.message import CheckinMessage
-        c = CheckinMessage()
-        a = CheckinMessage(body='Update of /cvs-repository/blah\n'
-                                'In directory cvs.zope.org:burgelburgel\n'
-                                '\n'
-                                'Added Files:\n'
-                                '      Tag: foomatic-branch\n'
-                                '\t__init__.py foo.py\n'
-                                'Log Message:\n'
-                                'do something\n',
-                           branch='foomatic-branch')
-        state = a.__getstate__()
-        del state['branch']
-        b = CheckinMessage()
-        b.__setstate__(state)
-        self.assertEquals(b.branch, a.branch)
-        self.assertEquals(a.__dict__, b.__dict__)
-
-    def test_setstate_branch2(self):
-        from zopeproducts.z3checkins.message import CheckinMessage
-        c = CheckinMessage()
-        a = CheckinMessage(body='Update of /cvs-repository/blah\n'
-                                'In directory cvs.zope.org:burgelburgel\n'
-                                '\n'
-                                'Added Files:\n'
-                                '\t__init__.py foo.py\n'
-                                'Log Message:\n'
-                                'do something\n'
-                                '\n'
-                                '=== Decoy ===\n'
-                                '      Tag: foomatic-branch\n')
-        state = a.__getstate__()
-        del state['branch']
-        b = CheckinMessage()
-        b.__setstate__(state)
-        self.assertEquals(b.branch, a.branch)
-        self.assertEquals(a.__dict__, b.__dict__)
-
 
 class TestCheckinMessageParser(unittest.TestCase):
 
@@ -221,15 +194,25 @@
 No conflicts created by this import
 """
 
+    simple_msg = """\
+From: John Doe <john@example.com>
+Subject: Something happened!
+Date: Wed, 29 Jul 2003 14:42:11 +0200
+Message-Id: <q$w$e$r$t$y@example.com>
+
+This is just a simple message.
+"""
+
     def test_interface(self):
         from zopeproducts.z3checkins.message import CheckinMessageParser
-        verifyObject(ICheckinMessageParser, CheckinMessageParser())
+        verifyObject(IMessageParser, CheckinMessageParser())
 
     def test_parser1(self):
         from zopeproducts.z3checkins.message import CheckinMessageParser
         from zopeproducts.z3checkins.message import FixedTimezone
         parser = CheckinMessageParser()
         msg = parser.parse(StringIO(self.sample_msg1))
+        self.assert_(ICheckinMessage.isImplementedBy(msg))
         self.assertEquals(msg.message_id, "<42@bar.com>")
         self.assertEquals(msg.author, "Foo Bar <foo.bar@bar.com>")
         self.assertEquals(msg.author_name, "Foo Bar")
@@ -242,13 +225,14 @@
 Ipsum suum dolores quantum est er nonsensicum textum writum esmum inum tuum
 lineum furum testum logum messageum.""")
         self.assertEquals(msg.body,
-                          self.sample_msg1.split("\n\n", 1)[1].strip())
+                          self.sample_msg1.split("\n\n", 1)[1])
 
     def test_parser2(self):
         from zopeproducts.z3checkins.message import CheckinMessageParser
         from zopeproducts.z3checkins.message import FixedTimezone
         parser = CheckinMessageParser()
         msg = parser.parse(StringIO(self.sample_msg2))
+        self.assert_(ICheckinMessage.isImplementedBy(msg))
         self.assertEquals(msg.message_id, "<42@bar.com>")
         self.assertEquals(msg.author, "Foo Bar <foo.bar@bar.com>")
         self.assertEquals(msg.author_name, "Foo Bar")
@@ -261,13 +245,14 @@
 Ipsum suum dolores quantum est er nonsensicum textum writum esmum inum tuum
 lineum furum testum logum messageum.""")
         self.assertEquals(msg.body,
-                          self.sample_msg2.split("\n\n", 1)[1].strip())
+                          self.sample_msg2.split("\n\n", 1)[1])
 
     def test_parser_importmsg(self):
         from zopeproducts.z3checkins.message import CheckinMessageParser
         from zopeproducts.z3checkins.message import FixedTimezone
         parser = CheckinMessageParser()
         msg = parser.parse(StringIO(self.sample_import_msg))
+        self.assert_(ICheckinMessage.isImplementedBy(msg))
         self.assertEquals(msg.message_id, "<42@bar.com>")
         self.assertEquals(msg.author, "Foo Bar <foo.bar@bar.com>")
         self.assertEquals(msg.author_name, "Foo Bar")
@@ -280,12 +265,27 @@
 Ipsum suum dolores quantum est er nonsensicum textum writum esmum inum tuum
 lineum furum testum logum messageum.""")
         self.assertEquals(msg.body,
-                          self.sample_import_msg.split("\n\n", 1)[1].strip())
+                          self.sample_import_msg.split("\n\n", 1)[1])
+
+    def test_parser_simplemsg(self):
+        from zopeproducts.z3checkins.message import CheckinMessageParser
+        from zopeproducts.z3checkins.message import FixedTimezone
+        parser = CheckinMessageParser()
+        msg = parser.parse(StringIO(self.simple_msg))
+        self.assert_(IMessage.isImplementedBy(msg))
+        self.assert_(not ICheckinMessage.isImplementedBy(msg))
+        self.assertEquals(msg.message_id, "<q$w$e$r$t$y@example.com>")
+        self.assertEquals(msg.author, "John Doe <john@example.com>")
+        self.assertEquals(msg.author_name, "John Doe")
+        self.assertEquals(msg.author_email, "john@example.com")
+        self.assertEquals(msg.date, datetime(2003, 07, 29, 14, 42, 11,
+                                             tzinfo=FixedTimezone(2*60)))
+        self.assertEquals(msg.body, self.simple_msg.split("\n\n", 1)[1])
 
 
 class MessageStub:
 
-    __implements__ = ICheckinMessage
+    implements(ICheckinMessage)
 
     def __init__(self, data=None, date=None, body=None, log_message='',
                        message_id="<message@id>"):
@@ -296,28 +296,28 @@
         self.message_id = message_id
 
 
-class TestCheckinMessageAdapter(unittest.TestCase):
+class TestMessageContainerAdapter(unittest.TestCase):
 
     def test_interface(self):
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
-        verifyObject(ICheckinMessageArchive, CheckinMessageAdapter({}))
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
+        verifyObject(IMessageArchive, MessageContainerAdapter({}))
 
     def test_len(self):
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
-        a = CheckinMessageAdapter({})
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
+        a = MessageContainerAdapter({})
         self.assertEquals(len(a), 0)
-        a = CheckinMessageAdapter({'1': 2, '3': 'abc'})
+        a = MessageContainerAdapter({'1': 2, '3': 'abc'})
         self.assertEquals(len(a), 0)
-        a = CheckinMessageAdapter({'1': 2, '3': 'abc', 4: MessageStub()})
+        a = MessageContainerAdapter({'1': 2, '3': 'abc', 4: MessageStub()})
         self.assertEquals(len(a), 1)
 
     def test_getitem(self):
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
-        a = CheckinMessageAdapter({'1': 2, '3': 'abc',
-                                   '4': MessageStub(date=1, message_id='1'),
-                                   '5': MessageStub(date=4, message_id='2'),
-                                   '6': MessageStub(date=3, message_id='3'),
-                                   '7': MessageStub(date=2, message_id='4')})
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
+        a = MessageContainerAdapter({'1': 2, '3': 'abc',
+                                     '4': MessageStub(date=1, message_id='1'),
+                                     '5': MessageStub(date=4, message_id='2'),
+                                     '6': MessageStub(date=3, message_id='3'),
+                                     '7': MessageStub(date=2, message_id='4')})
         self.assertEquals(a[0].message_id, '1')
         self.assertEquals(a[1].message_id, '4')
         self.assertEquals(a[2].message_id, '3')
@@ -332,25 +332,25 @@
         self.assertEquals(len(a[3:1]), 0)
 
     def test_iter(self):
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
-        a = CheckinMessageAdapter({'1': 2, '3': 'abc',
-                                   '4': MessageStub(date=1, message_id='1'),
-                                   '5': MessageStub(date=4, message_id='2'),
-                                   '6': MessageStub(date=3, message_id='3'),
-                                   '7': MessageStub(date=2, message_id='4')})
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
+        a = MessageContainerAdapter({'1': 2, '3': 'abc',
+                                     '4': MessageStub(date=1, message_id='1'),
+                                     '5': MessageStub(date=4, message_id='2'),
+                                     '6': MessageStub(date=3, message_id='3'),
+                                     '7': MessageStub(date=2, message_id='4')})
         b = [x.message_id for x in a]
         self.assertEquals(b, ['1', '4', '3', '2'])
         self.assert_(MessageStub(message_id='5') not in a)
         self.assert_(a.context['6'] in a)
 
     def test_index(self):
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
         m1 = MessageStub(date=1, message_id='1')
         m2 = MessageStub(date=4, message_id='2')
         m3 = MessageStub(date=3, message_id='3')
         m4 = MessageStub(date=2, message_id='4')
-        a = CheckinMessageAdapter({'1': 2, '3': 'abc',
-                                   '4': m1, '5': m2, '6': m3, '7': m4})
+        a = MessageContainerAdapter({'1': 2, '3': 'abc',
+                                     '4': m1, '5': m2, '6': m3, '7': m4})
         self.assertEquals(a.index(m1), 0)
         self.assertEquals(a.index(m4), 1)
         self.assertEquals(a.index(m3), 2)
@@ -360,7 +360,7 @@
 
 class ParserStub:
 
-    __implements__ = ICheckinMessageParser
+    implements(IMessageParser)
 
     def parse(self, data):
         return MessageStub(data=data)
@@ -377,7 +377,7 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        getService(None, 'Utilities').provideUtility(ICheckinMessageParser,
+        getService(None, 'Utilities').provideUtility(IMessageParser,
                                                      ParserStub())
 
     def test_createAndAdd(self):
@@ -445,10 +445,10 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
         getService(None, 'Adapters').provideAdapter(None,
-                                                    ICheckinMessageArchive,
-                                                    CheckinMessageAdapter)
+                                                    IMessageArchive,
+                                                    MessageContainerAdapter)
 
     def test_checkins(self):
         from zopeproducts.z3checkins.message import ContainerView
@@ -503,7 +503,7 @@
         res = view.checkins()
         self.assertEquals(len(res), 4)
         self.assertEquals(res[0].date, 4)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assert_(IBookmark.isImplementedBy(res[1]))
         self.assertEquals(res[2].date, 2)
         self.assertEquals(res[3].date, 1)
 
@@ -511,7 +511,7 @@
         res = view.checkins()
         self.assertEquals(len(res), 4)
         self.assertEquals(res[0].date, 4)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assert_(IBookmark.isImplementedBy(res[1]))
         self.assertEquals(res[2].date, 2)
         self.assertEquals(res[3].date, 1)
 
@@ -519,16 +519,16 @@
         res = view.checkins()
         self.assertEquals(len(res), 5)
         self.assertEquals(res[0].date, 4)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assert_(IBookmark.isImplementedBy(res[1]))
         self.assertEquals(res[2].date, 2)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[3]))
+        self.assert_(IBookmark.isImplementedBy(res[3]))
         self.assertEquals(res[4].date, 1)
 
         res = view.checkins(start=1, size=1)
         self.assertEquals(len(res), 3)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[0]))
+        self.assert_(IBookmark.isImplementedBy(res[0]))
         self.assertEquals(res[1].date, 2)
-        self.assert_(ICheckinBookmark.isImplementedBy(res[2]))
+        self.assert_(IBookmark.isImplementedBy(res[2]))
 
     def test_bookmarks(self):
         from zopeproducts.z3checkins.message import ContainerView
@@ -687,7 +687,7 @@
         view.bookmarks = lambda: [1]
         provideView(ICheckinMessage, 'html', IUnitTestPresentation,
                     MessageTestView)
-        provideView(ICheckinBookmark, 'html', IUnitTestPresentation,
+        provideView(IBookmark, 'html', IUnitTestPresentation,
                     BookmarkTestView)
 
         res = view.renderCheckins()
@@ -724,10 +724,10 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        from zopeproducts.z3checkins.message import CheckinMessageAdapter
+        from zopeproducts.z3checkins.message import MessageContainerAdapter
         getService(None, 'Adapters').provideAdapter(None,
-                                                    ICheckinMessageArchive,
-                                                    CheckinMessageAdapter)
+                                                    IMessageArchive,
+                                                    MessageContainerAdapter)
 
     def test_body_strange(self):
         from zopeproducts.z3checkins.message import CheckinMessageView
@@ -974,7 +974,7 @@
     suite.addTest(unittest.makeSuite(TestISODateTimeFormatter))
     suite.addTest(unittest.makeSuite(TestCheckinMessage))
     suite.addTest(unittest.makeSuite(TestCheckinMessageParser))
-    suite.addTest(unittest.makeSuite(TestCheckinMessageAdapter))
+    suite.addTest(unittest.makeSuite(TestMessageContainerAdapter))
     suite.addTest(unittest.makeSuite(TestMessageUpload))
     suite.addTest(unittest.makeSuite(TestContainerView))
     suite.addTest(unittest.makeSuite(TestCheckinMessageView))