[CMF-checkins] CVS: CMF/CMFDefault/tests - test_Document.py:1.26 test_utils.py:1.8

Yvo Schubbe schubbe@web.de
Wed, 5 Feb 2003 12:51:25 -0500


Update of /cvs-repository/CMF/CMFDefault/tests
In directory cvs.zope.org:/tmp/cvs-serv4118/CMFDefault/tests

Modified Files:
	test_Document.py test_utils.py 
Log Message:
Merged yuppie-collector041-branch:
- Changed behavior of bodyfinder and html_headcheck.
- Fixed header stripping in edit and PUT. (Collector #41)

=== CMF/CMFDefault/tests/test_Document.py 1.25 => 1.26 ===
--- CMF/CMFDefault/tests/test_Document.py:1.25	Fri Jun  7 18:43:04 2002
+++ CMF/CMFDefault/tests/test_Document.py	Wed Feb  5 12:51:22 2003
@@ -1,4 +1,11 @@
 from unittest import TestSuite, makeSuite, main
+
+try:
+    from Interface.Verify import verifyClass
+except ImportError:
+    # for Zope versions before 2.6.0
+    from Interface import verify_class_implementation as verifyClass
+
 from StringIO import StringIO
 from re import compile
 
@@ -15,6 +22,7 @@
 from Products.CMFCore.tests.base.content import STX_NO_HEADERS_BUT_COLON
 from Products.CMFCore.tests.base.content import SIMPLE_STRUCTUREDTEXT
 from Products.CMFCore.tests.base.content import SIMPLE_HTML
+from Products.CMFCore.tests.base.content import SIMPLE_XHTML
 
 from Products.CMFDefault.Document import Document
 
@@ -32,30 +40,25 @@
         self.assertEqual( d.text_format, 'structured-text' )
         self.assertEqual( d._stx_level, 1 )
 
-    def test_BasicHtmlPUT(self):
-        self.REQUEST['BODY'] = BASIC_HTML
+    def test_editBasicHTML(self):
         d = self.d
-        d.PUT(self.REQUEST, self.RESPONSE)
+        d.edit('html', BASIC_HTML)
+        self.failUnless( hasattr(d, 'cooked_text') )
         self.assertEqual( d.Format(), 'text/html' )
-        self.assertEqual( d.title, 'Title in tag' )
         self.assertEqual( d.text.find('</body>'), -1 )
-        self.assertEqual( d.Description(), 'Describe me' )
-        self.assertEqual( len(d.Contributors()), 3 )
-        self.assertEqual( d.Contributors()[-1], 'Benotz, Larry J (larry@benotz.stuff)' )
+        self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ' )
 
         # Since the format is html, the STX level operands should
         # have no effect.
         ct = d.CookedBody(stx_level=3, setlevel=1)
         self.assertEqual( d._stx_level, 1 )
 
-        subj = list(d.Subject())
-        self.assertEqual( len(subj), 4 )
-        subj.sort()
-        self.assertEqual( subj, [ 'content management'
-                                , 'framework'
-                                , 'unit tests'
-                                , 'zope'
-                                ] )
+    def test_editSimpleXHTML(self):
+        d = self.d
+        d.edit('html', SIMPLE_XHTML)
+        self.failUnless( hasattr(d, 'cooked_text') )
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ')
 
     def test_UpperedHtml(self):
         self.REQUEST['BODY'] = BASIC_HTML.upper()
@@ -86,16 +89,6 @@
         self.assertEqual( d.Format(), 'text/html' )
         self.assertEqual( d.Description(), 'Describe me' )
 
-    def test_EditStripHTMLToBody(self):
-        # bodyfind should strip away everything but the contents of the body
-        # tag.
-        self.REQUEST['BODY'] = BASIC_HTML
-        d = self.d
-        d.PUT(self.REQUEST, self.RESPONSE)
-        self.failUnless( hasattr(d, 'cooked_text') )
-        self.assertEqual( d.Format(), 'text/html' )
-        self.assertEquals(d.cooked_text, '\n  <h1>Not a lot here</h1>\n ')
-
     def test_EditPlainDocumentWithEmbeddedHTML(self):
         d = self.d
         d.edit('structured-text', FAUX_HTML_LEADING_TEXT)
@@ -262,6 +255,25 @@
                              , text=STX_NO_HEADERS_BUT_COLON)
         self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )
 
+    def test_interface(self):
+        from Products.CMFCore.interfaces.Dynamic \
+                import DynamicType as IDynamicType
+        from Products.CMFCore.interfaces.Contentish \
+                import Contentish as IContentish
+        from Products.CMFCore.interfaces.DublinCore \
+                import DublinCore as IDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import CatalogableDublinCore as ICatalogableDublinCore
+        from Products.CMFCore.interfaces.DublinCore \
+                import MutableDublinCore as IMutableDublinCore
+
+        verifyClass(IDynamicType, Document)
+        verifyClass(IContentish, Document)
+        verifyClass(IDublinCore, Document)
+        verifyClass(ICatalogableDublinCore, Document)
+        # XXX: verifyClass doesn't work with WorkflowMethod wrappers.
+        # verifyClass(IMutableDublinCore, Document)
+
 
 class TestFTPGet( RequestTest ):
 
@@ -345,6 +357,40 @@
         RequestTest.setUp(self)
         self.d = Document('foo')
 
+    def test_PUTBasicHTML(self):
+        self.REQUEST['BODY'] = BASIC_HTML
+        d = self.d
+        r = d.PUT(self.REQUEST, self.RESPONSE)
+        self.failUnless( hasattr(d, 'cooked_text') )
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.title, 'Title in tag' )
+        self.assertEqual( d.text.find('</body>'), -1 )
+        self.assertEqual( d.Description(), 'Describe me' )
+        self.assertEqual( len(d.Contributors()), 3 )
+        self.assertEqual( d.Contributors()[-1],
+                          'Benotz, Larry J (larry@benotz.stuff)' )
+        self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ' )
+        self.assertEqual( r.status, 204 )
+
+        subj = list(d.Subject())
+        self.assertEqual( len(subj), 4 )
+        subj.sort()
+        self.assertEqual( subj, [ 'content management'
+                                , 'framework'
+                                , 'unit tests'
+                                , 'zope'
+                                ] )
+
+    def test_PUTSimpleXHTML(self):
+        self.REQUEST['BODY'] = SIMPLE_XHTML
+        d = self.d
+        r = d.PUT(self.REQUEST, self.RESPONSE)
+        self.failUnless( hasattr(d, 'cooked_text') )
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Description(), 'Describe me' )
+        self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ' )
+        self.assertEqual( r.status, 204 )
+
     def test_PutStructuredTextWithHTML(self):
             
         self.REQUEST['BODY'] = STX_WITH_HTML
@@ -366,14 +412,6 @@
         html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
         self.REQUEST['BODY'] = html
         
-        r = self.d.PUT(self.REQUEST, self.RESPONSE)
-        self.assertEqual( self.d.Format(), 'text/html' )
-        self.assertEqual( self.d.Description(), 'Describe me' )
-        self.assertEqual( r.status, 204 )
-
-    def test_PutHtml(self):
-        
-        self.REQUEST['BODY'] = BASIC_HTML
         r = self.d.PUT(self.REQUEST, self.RESPONSE)
         self.assertEqual( self.d.Format(), 'text/html' )
         self.assertEqual( self.d.Description(), 'Describe me' )


=== CMF/CMFDefault/tests/test_utils.py 1.7 => 1.8 ===
--- CMF/CMFDefault/tests/test_utils.py:1.7	Mon Jan  6 15:43:39 2003
+++ CMF/CMFDefault/tests/test_utils.py	Wed Feb  5 12:51:22 2003
@@ -1,9 +1,18 @@
-from unittest import TestCase,makeSuite,main
+from unittest import TestCase, makeSuite, main
 
 import Zope
+from Products.CMFCore.tests.base.content import FAUX_HTML_LEADING_TEXT
+from Products.CMFCore.tests.base.content import SIMPLE_HTML
+from Products.CMFCore.tests.base.content import SIMPLE_STRUCTUREDTEXT
+from Products.CMFCore.tests.base.content import SIMPLE_XHTML
+from Products.CMFCore.tests.base.content import STX_WITH_HTML
+
 from Products.CMFDefault.utils import parseHeadersBody, tuplize, comma_split
+from Products.CMFDefault.utils import bodyfinder
+from Products.CMFDefault.utils import html_headcheck
 from Products.CMFDefault.utils import seq_strip
 
+
 class DefaultUtilsTests(TestCase):
     COMMON_HEADERS = '''Author: Tres Seaver
 Title: Test Products.CMFDefault.utils.parseHeadersBody'''
@@ -58,6 +67,26 @@
         assert( len( headers ) == 3, '%d!' % len( headers ) )
         assert( preloaded[ 'Author' ] != headers[ 'Author' ] )
         assert( preloaded[ 'text_format' ] == headers[ 'text_format' ] )
+
+    def test_bodyfinder(self):
+        self.assertEqual( bodyfinder(FAUX_HTML_LEADING_TEXT),
+                          '\n  <h1>Not a lot here</h1>\n ' )
+        self.assertEqual( bodyfinder(SIMPLE_HTML),
+                          '\n  <h1>Not a lot here</h1>\n ' )
+        self.assertEqual( bodyfinder(SIMPLE_STRUCTUREDTEXT),
+                          SIMPLE_STRUCTUREDTEXT )
+        self.assertEqual( bodyfinder(SIMPLE_XHTML),
+                          '\n  <h1>Not a lot here</h1>\n ' )
+        self.assertEqual( bodyfinder(STX_WITH_HTML),
+                          '<p>Hello world, I am Bruce.</p>' )
+
+    def test_html_headcheck(self):
+        self.assertEqual( html_headcheck(FAUX_HTML_LEADING_TEXT), 0 )
+        self.assertEqual( html_headcheck(SIMPLE_HTML), 1 )
+        self.assertEqual( html_headcheck(SIMPLE_STRUCTUREDTEXT), 0 )
+        self.assertEqual( html_headcheck(SIMPLE_XHTML), 1 )
+        self.assertEqual( html_headcheck(STX_WITH_HTML), 0 )
+
 
 def test_suite():
     return makeSuite(DefaultUtilsTests)