[Zope3-checkins] CVS: Zope3/src/zope/app/content/tests - test_zptpage.py:1.3

Steve Alexander steve@cat-box.net
Fri, 27 Dec 2002 15:34:20 -0500


Update of /cvs-repository/Zope3/src/zope/app/content/tests
In directory cvs.zope.org:/tmp/cvs-serv24831/src/zope/app/content/tests

Modified Files:
	test_zptpage.py 
Log Message:
Split zpt interfaces out into the zope/app/interfaces hierarchy.
Added an ISized adapter for zpt pages.


=== Zope3/src/zope/app/content/tests/test_zptpage.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/content/tests/test_zptpage.py:1.2	Wed Dec 25 09:12:48 2002
+++ Zope3/src/zope/app/content/tests/test_zptpage.py	Fri Dec 27 15:33:49 2002
@@ -19,8 +19,10 @@
 
 import unittest
 
-from zope.app.content.zpt import ZPTPage, \
-     SearchableText, IZPTPage
+from zope.interface.verify import verifyClass
+
+from zope.app.content.zpt import ZPTPage, SearchableText
+from zope.app.interfaces.content.zpt import IZPTPage
 from zope.app.interfaces.index.text.interfaces import ISearchableText
 from zope.component import getAdapter
 
@@ -39,7 +41,6 @@
         self.__dict__.update(kw)
 
 
-
 class ZPTPageTests(PlacelessSetup, unittest.TestCase):
 
     def setUp(self):
@@ -65,8 +66,6 @@
         page.setSource(html, content_type='text/plain')
         self.assertEqual(searchableText.getSearchableText(), [html])
 
-
-
     def testZPTRendering(self):
         page = ZPTPage()
         page.setSource(
@@ -93,10 +92,45 @@
             '</a></body></html>'
             )
 
+class DummyZPT:
+
+    def __init__(self, source):
+        self.source = source
+
+    def getSource(self):
+        return self.source
+
+class SizedTests(unittest.TestCase):
+
+    def testInterface(self):
+        from zope.app.interfaces.size import ISized
+        from zope.app.content.zpt import Sized
+        self.failUnless(ISized.isImplementedByInstancesOf(Sized))
+        self.failUnless(verifyClass(ISized, Sized))
+
+    def test_zeroSized(self):
+        from zope.app.content.zpt import Sized
+        s = Sized(DummyZPT(''))
+        self.assertEqual(s.sizeForSorting(), ('line', 0))
+        self.assertEqual(s.sizeForDisplay(), u'0 lines')
+
+    def test_oneSized(self):
+        from zope.app.content.zpt import Sized
+        s = Sized(DummyZPT('one line'))
+        self.assertEqual(s.sizeForSorting(), ('line', 1))
+        self.assertEqual(s.sizeForDisplay(), u'1 line')
+        
+    def test_arbitrarySize(self):
+        from zope.app.content.zpt import Sized
+        s = Sized(DummyZPT('some line\n'*5))
+        self.assertEqual(s.sizeForSorting(), ('line', 5))
+        self.assertEqual(s.sizeForDisplay(), u'5 lines')
 
 
 def test_suite():
-    return unittest.makeSuite(ZPTPageTests)
+    return unittest.TestSuite((unittest.makeSuite(ZPTPageTests),
+                               unittest.makeSuite(SizedTests)
+                             ))
 
 if __name__=='__main__':
     unittest.TextTestRunner().run(test_suite())