[Zope3-checkins] CVS: Products3/z3checkins/tests - test_message.py:1.6

Marius Gedminas mgedmin@codeworks.lt
Wed, 16 Apr 2003 18:01:49 -0400


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

Modified Files:
	test_message.py 
Log Message:
z3checkins:
- updated README
- added three new TODO items
- store last 5 visits in a cookie and display them as bookmarks between
  messages


=== Products3/z3checkins/tests/test_message.py 1.5 => 1.6 ===
--- Products3/z3checkins/tests/test_message.py:1.5	Tue Apr  8 13:35:10 2003
+++ Products3/z3checkins/tests/test_message.py	Wed Apr 16 18:01:48 2003
@@ -16,8 +16,10 @@
 from zope.proxy.context import getWrapperContext, getWrapperData
 from zope.proxy.context import ContextWrapper
 
-from zopeproducts.z3checkins.interfaces import ICheckinMessage, ICheckinMessageParser
+from zopeproducts.z3checkins.interfaces import ICheckinMessage
+from zopeproducts.z3checkins.interfaces import ICheckinMessageParser
 from zopeproducts.z3checkins.interfaces import ICheckinMessageArchive
+from zopeproducts.z3checkins.interfaces import ICheckinBookmark
 
 
 class TestFixedTimezone(unittest.TestCase):
@@ -398,6 +400,18 @@
         self.assertEquals(view.context.added.data, "Ipsum suum")
 
 
+class RequestStub(dict):
+
+    _cookies = ()
+
+    def __init__(self, **kw):
+        super(RequestStub, self).__init__()
+        self.update(kw)
+        self.response = self
+
+    def setCookie(self, name, value, **kw):
+        self._cookies += (name, value, kw)
+
 class TestContainerView(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
@@ -407,11 +421,11 @@
                                                     ICheckinMessageArchive,
                                                     CheckinMessageAdapter)
 
-    def test_last_checkins(self):
+    def test_checkins(self):
         from zopeproducts.z3checkins.message import ContainerView
         view = ContainerView()
-        view.context = { 'x': 123, 'y': object(), 'z': MessageStub(date=1),
-                         'a': MessageStub(date=2), 'c': MessageStub(date=3) }
+        view.context = {'x': 123, 'y': object(), 'z': MessageStub(date=1),
+                        'a': MessageStub(date=2), 'c': MessageStub(date=3)}
         view.request = {}
         res = view.checkins()
         self.assertEquals(len(res), 3)
@@ -426,11 +440,11 @@
         self.assertEquals(getWrapperData(res[1])['name'], 'a')
         self.assertEquals(getWrapperData(res[2])['name'], 'z')
 
-    def test_last_checkins_limited(self):
+    def test_checkins_limited(self):
         from zopeproducts.z3checkins.message import ContainerView
         view = ContainerView()
-        view.context = { 'x': 123, 'y': object(), 'z': MessageStub(date=1),
-                         'a': MessageStub(date=2), 'c': MessageStub(date=3) }
+        view.context = {'x': 123, 'y': object(), 'z': MessageStub(date=1),
+                        'a': MessageStub(date=2), 'c': MessageStub(date=3)}
         view.request = {}
         res = view.checkins(size=2)
         self.assertEquals(len(res), 2)
@@ -449,6 +463,155 @@
         self.assertEquals(getWrapperContext(res[1]), view.context)
         self.assertEquals(getWrapperData(res[0])['name'], 'a')
         self.assertEquals(getWrapperData(res[1])['name'], 'z')
+
+    def test_checkins_bookmarks(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(), 'z': MessageStub(date=1),
+                        'a': MessageStub(date=2), 'c': MessageStub(date=4)}
+        view.request = {}
+        view.bookmarks = lambda: [3]
+        res = view.checkins()
+        self.assertEquals(len(res), 4)
+        self.assertEquals(res[0].date, 4)
+        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assertEquals(res[2].date, 2)
+        self.assertEquals(res[3].date, 1)
+
+        view.bookmarks = lambda: [2]
+        res = view.checkins()
+        self.assertEquals(len(res), 4)
+        self.assertEquals(res[0].date, 4)
+        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assertEquals(res[2].date, 2)
+        self.assertEquals(res[3].date, 1)
+
+        view.bookmarks = lambda: [0, 1, 2, 3, 4, 5, 6, 2, 3, 1]
+        res = view.checkins()
+        self.assertEquals(len(res), 5)
+        self.assertEquals(res[0].date, 4)
+        self.assert_(ICheckinBookmark.isImplementedBy(res[1]))
+        self.assertEquals(res[2].date, 2)
+        self.assert_(ICheckinBookmark.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.assertEquals(res[1].date, 2)
+        self.assert_(ICheckinBookmark.isImplementedBy(res[2]))
+
+    def test_bookmarks(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.request = {}
+        self.assertEquals(view.bookmarks(), [])
+        view.request = {'bookmarks': '2003-01-04T21:33:04-05:00'}
+        self.assertEquals(view.bookmarks(),
+                          [datetime(2003, 01, 04, 21, 33, 04,
+                                    tzinfo=FixedTimezone(-5*60))])
+        view.request = {'bookmarks': '2003-01-04T21:33:04-05:00 '
+                                     'errors are ignored '
+                                     '2004-05-06T07:08:09+10:00 '
+                                     '2002-02-02T02:02:02+02:00 '
+                                     '2005-02-29T07:08:09+10:00'}
+        self.assertEquals(view.bookmarks(),
+                          [datetime(2003, 1, 4, 21, 33, 4,
+                                    tzinfo=FixedTimezone(-5*60)),
+                           datetime(2004, 5, 6, 7, 8, 9,
+                                    tzinfo=FixedTimezone(10*60)),
+                           datetime(2002, 2, 2, 2, 2, 2,
+                                    tzinfo=FixedTimezone(2*60))])
+
+    def test_placeBookmark_empty_archive(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.context = {}
+        view.request = RequestStub()
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies, ())
+
+    def test_placeBookmark_empty_bookmarks(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(),
+                        'z': MessageStub(date=datetime(2003, 1, 4, 21, 33, 4,
+                                                tzinfo=FixedTimezone(-5*60)))}
+        view.request = RequestStub()
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies,
+                          ('bookmarks', '2003-01-04T21:33:04-05:00',
+                           {'max_age': 31536000}))
+
+    def test_placeBookmark_no_new_checkins(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(),
+                        'z': MessageStub(date=datetime(2003, 1, 4, 21, 33, 4,
+                                                tzinfo=FixedTimezone(-5*60)))}
+        view.request = RequestStub(bookmarks='2003-01-04T21:33:04-05:00 '
+                                             'errors are ignored '
+                                             '2002-02-02T02:02:02+02:00')
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies, ())
+
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(),
+                        'z': MessageStub(date=datetime(2003, 1, 4, 21, 33, 4,
+                                                tzinfo=FixedTimezone(-5*60)))}
+        view.request = RequestStub(bookmarks='2004-01-04T21:33:04-05:00 '
+                                             'errors are ignored '
+                                             '2002-02-02T02:02:02+02:00')
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies, ())
+
+    def test_placeBookmark_new_checkins(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(),
+                        'z': MessageStub(date=datetime(2003, 1, 4, 21, 33, 4,
+                                                tzinfo=FixedTimezone(-5*60))),
+                        'w': MessageStub(date=datetime(2003, 1, 6, 22, 33, 44,
+                                                tzinfo=FixedTimezone(+3*60)))}
+        view.request = RequestStub(bookmarks='2003-01-04T21:33:04-05:00 '
+                                             'errors are ignored '
+                                             '2002-02-02T02:02:02+02:00')
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies,
+                          ('bookmarks', '2002-02-02T02:02:02+02:00 '
+                                        '2003-01-04T21:33:04-05:00 '
+                                        '2003-01-06T22:33:44+03:00',
+                           {'max_age': 31536000}))
+
+    def test_placeBookmark_new_checkins_overflow(self):
+        from zopeproducts.z3checkins.message import ContainerView
+        from zopeproducts.z3checkins.message import FixedTimezone
+        view = ContainerView()
+        view.context = {'x': 123, 'y': object(),
+                        'z': MessageStub(date=datetime(2003, 1, 4, 21, 33, 4,
+                                                tzinfo=FixedTimezone(-5*60))),
+                        'w': MessageStub(date=datetime(2003, 1, 6, 22, 33, 44,
+                                                tzinfo=FixedTimezone(+3*60)))}
+        view.request = RequestStub(bookmarks='2003-01-04T21:33:04-05:00 '
+                                             'errors are ignored '
+                                             '2002-01-01T02:02:02+02:00 '
+                                             '2002-01-02T02:02:02+02:00 '
+                                             '2002-01-03T02:02:02+02:00 '
+                                             '2002-01-04T02:02:02+02:00 '
+                                             '2002-02-02T02:02:02+02:00 ')
+        view.placeBookmark()
+        self.assertEquals(view.request._cookies,
+                          ('bookmarks', '2002-01-03T02:02:02+02:00 '
+                                        '2002-01-04T02:02:02+02:00 '
+                                        '2002-02-02T02:02:02+02:00 '
+                                        '2003-01-04T21:33:04-05:00 '
+                                        '2003-01-06T22:33:44+03:00',
+                           {'max_age': 31536000}))
 
 
 def diff(a, b):