[CMF-checkins] CVS: Products/CMFDefault/tests - test_Document.py:1.20

Tres Seaver tseaver@zope.com
Mon, 17 Dec 2001 13:23:00 -0500


Update of /cvs-repository/Products/CMFDefault/tests
In directory cvs.zope.org:/tmp/cvs-serv6914/CMFDefault/tests

Modified Files:
	test_Document.py 
Log Message:
 - Merge fix for Tracker #435 from branch.

=== Products/CMFDefault/tests/test_Document.py 1.19 => 1.20 ===
-from utils import fakeRequest, fakeResponse
+from Products.CMFDefault.tests.utils import fakeRequest, fakeResponse
 from Products.CMFDefault.Document import Document
 #" 
 DOCTYPE = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'''
@@ -129,72 +129,70 @@
 
     def test_Empty(self):
         d = Document('foo', text_format='structured-text')
-        assert d.title == ''
-        assert d.description == ''
-        assert d.text == ''
-        assert d.text_format == 'structured-text'
-        assert d._stx_level == 1
+        self.assertEqual( d.title, '' )
+        self.assertEqual( d.description, '' )
+        self.assertEqual( d.text, '' )
+        self.assertEqual( d.text_format, 'structured-text' )
+        self.assertEqual( d._stx_level, 1 )
 
     def test_BasicHtmlPUT(self):
         REQUEST = fakeRequest()
         REQUEST['BODY'] = BASIC_HTML
         d = Document('foo')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Format() == 'text/html'
-        assert d.title == 'Title in tag'
-        assert string.find(d.text, '</body>') == -1
-        assert d.Description() == 'Describe me'
-        assert len(d.Contributors()) == 3
-        assert d.Contributors()[-1] == 'Benotz, Larry J (larry@benotz.stuff)'
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.title, 'Title in tag' )
+        self.assertEqual( string.find(d.text, '</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)' )
 
         # Since the format is html, the STX level operands should
         # have no effect.
         ct = d.CookedBody(stx_level=3, setlevel=1)
-        assert d._stx_level == 1
+        self.assertEqual( d._stx_level, 1 )
 
         subj = list(d.Subject())
-        assert len(subj) == 4
+        self.assertEqual( len(subj), 4 )
         subj.sort()
-        assert subj == [
-            'content management',
-            'framework',
-            'unit tests',
-            'zope'
-            ]
+        self.assertEqual( subj, [ 'content management'
+                                , 'framework'
+                                , 'unit tests'
+                                , 'zope'
+                                ] )
 
     def test_UpperedHtml(self):
         REQUEST=fakeRequest()
         REQUEST['BODY'] = string.upper(BASIC_HTML)
         d = Document('foo')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Format() == 'text/html'
-        assert d.title == 'TITLE IN TAG'
-        assert string.find(d.text, '</BODY') == -1
-        assert d.Description() == 'DESCRIBE ME'
-        assert len(d.Contributors()) == 3
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.title, 'TITLE IN TAG' )
+        self.assertEqual( string.find(d.text, '</BODY'), -1 )
+        self.assertEqual( d.Description(), 'DESCRIBE ME' )
+        self.assertEqual( len(d.Contributors()), 3 )
 
     def test_EntityInTitle(self):
         REQUEST=fakeRequest()
         REQUEST['BODY'] = ENTITY_IN_TITLE 
         d = Document('foo')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.title == '&Auuml;rger', "Title '%s' being lost" % (
-            d.title )
+        self.assertEqual( d.title, '&Auuml;rger' )
 
     def test_HtmlWithDoctype(self):
         REQUEST=fakeRequest()
         d = Document('foo')
         REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Description() == 'Describe me'
+        self.assertEqual( d.Description(), 'Describe me' )
 
     def test_HtmlWithoutNewlines(self):
         REQUEST=fakeRequest()
         d = Document('foo')
         REQUEST['BODY'] = string.join(string.split(BASIC_HTML, '\n'), '')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Format() == 'text/html'
-        assert d.Description() == 'Describe me'
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Description(), 'Describe me' )
 
     def test_BigHtml(self):
         REQUEST = fakeRequest()
@@ -206,7 +204,7 @@
         REQUEST['BODY'] = HTML_TEMPLATE % {'title': 'big document',
                                 'body': body}
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.CookedBody() == body
+        self.assertEqual( d.CookedBody(), body )
 
     def test_BigHtml_via_upload(self):
         d = Document('foo')
@@ -219,90 +217,95 @@
         from StringIO import StringIO
         file = StringIO( html )
         d.edit(text_format='html', text='', file=file)
-        assert d.CookedBody() == body
+        self.assertEqual( d.CookedBody(), body )
         
 
     def test_EditStructuredTextWithHTML(self):
         d = Document('foo')
         d.edit(text_format='structured-text', text=STX_WITH_HTML)
         
-        assert d.Format() == 'text/plain', "%s != %s" % (
-            d.Format(), 'text/plain')
+        self.assertEqual( d.Format(), 'text/plain' )
 
     def test_StructuredText(self):
         REQUEST=fakeRequest()
         REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
         d = Document('foo')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert hasattr(d, 'cooked_text')
-        assert d.Format() == 'text/plain'
-        assert d.Title() == 'My Document'
-        assert d.Description() == 'A document by me'
-        assert len(d.Contributors()) == 3
-        assert string.find(d.cooked_text, '<p>') >= 0
-        assert string.find(d.CookedBody(), '<h1') >= 0
+        self.failUnless( hasattr(d, 'cooked_text') )
+        self.assertEqual( d.Format(), 'text/plain' )
+        self.assertEqual( d.Title(), 'My Document' )
+        self.assertEqual( d.Description(), 'A document by me' )
+        self.assertEqual( len(d.Contributors()), 3 )
+        self.failUnless( string.find(d.cooked_text, '<p>') >= 0 )
+        self.failUnless( string.find(d.CookedBody(), '<h1') >= 0 )
 
         # Make sure extra HTML is NOT found
-        assert string.find(d.cooked_text, '<title>') == -1, d.cooked_text
-        assert string.find(d.cooked_text, '<body>') == -1, d.cooked_text
+        self.failUnless( string.find(d.cooked_text, '<title>') < 0 )
+        self.failUnless( string.find(d.cooked_text, '<body>') < 0 )
 
         # test subject/keyword headers
         subj = list(d.Subject())
-        assert len(subj) == 4
+        self.assertEqual( len(subj), 4 )
         subj.sort()
-        assert subj == [
-            'content management',
-            'framework',
-            'unit tests',
-            'zope'
-            ]
+        self.assertEqual( subj, [ 'content management'
+                                , 'framework'
+                                , 'unit tests'
+                                , 'zope'
+                                ] )
 
     def test_STX_Levels(self):
         d = Document('foo')
         d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)
-        assert d._stx_level == 1
+        self.assertEqual( d._stx_level, 1 )
 
         ct = d.CookedBody()
-        assert string.find(d.CookedBody(), '<h1') >= 0
-        assert d._stx_level == 1
+        self.failUnless( string.find(d.CookedBody(), '<h1') >= 0 )
+        self.assertEqual( d._stx_level, 1 )
 
         ct = d.CookedBody(stx_level=2)
-        assert not (string.find(ct, '<h1') >= 0)
-        assert string.find(ct, '<h2') >= 0
-        assert d._stx_level == 1
+        self.failIf( (string.find(ct, '<h1') >= 0) )
+        self.failUnless( string.find(ct, '<h2') >= 0 )
+        self.assertEqual( d._stx_level, 1 )
 
         ct = d.CookedBody(stx_level=2, setlevel=1)
-        assert not (string.find(ct, '<h1') >= 0)
-        assert string.find(ct, '<h2') >= 0
-        assert d._stx_level == 2
+        self.failIf( (string.find(ct, '<h1') >= 0) )
+        self.failUnless( string.find(ct, '<h2') >= 0 )
+        self.assertEqual( d._stx_level, 2 )
 
         ct = d.CookedBody()
-        assert d._stx_level == 2
-        assert not (string.find(d.CookedBody(), '<h1') >= 0)
-        assert string.find(d.CookedBody(), '<h2') >= 0
+        self.assertEqual( d._stx_level, 2 )
+        self.failIf( (string.find(d.CookedBody(), '<h1') >= 0) )
+        self.failUnless( string.find(d.CookedBody(), '<h2') >= 0 )
 
     def test_Init(self):
         REQUEST=fakeRequest()
         REQUEST['BODY']=BASIC_STRUCTUREDTEXT
         d = Document('foo')
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Format() == 'text/plain'
-        assert d.Title() == 'My Document'
-        assert d.Description() == 'A document by me'
-        assert len(d.Contributors()) == 3
-        assert string.find(d.cooked_text, '<p>') >= 0
+        self.assertEqual( d.Format(), 'text/plain' )
+        self.assertEqual( d.Title(), 'My Document' )
+        self.assertEqual( d.Description(), 'A document by me' )
+        self.assertEqual( len(d.Contributors()), 3 )
+        self.failUnless( string.find(d.cooked_text, '<p>') >= 0 )
 
         d = Document('foo', text='')
         REQUEST['BODY']=BASIC_HTML
         d.PUT(REQUEST, RESPONSE=fakeResponse())
-        assert d.Format() == 'text/html'
-        assert d.Title() == 'Title in tag'
-        assert len(d.Contributors()) == 3
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Title(), 'Title in tag' )
+        self.assertEqual( len(d.Contributors()), 3 )
 
         d = Document('foo', text_format='structured-text', title='Foodoc')
-        assert d.text == ''
-        assert d.title == 'Foodoc'
-        assert d.Format() == 'text/plain'
+        self.assertEqual( d.text, '' )
+        self.failIf( d.CookedBody() )
+        self.assertEqual( d.title, 'Foodoc' )
+        self.assertEqual( d.Format(), 'text/plain' )
+
+        # Tracker issue 435:  initial text is not cooked.
+        d = Document('foo', text_format='structured-text', text=STX_NO_HEADERS)
+        self.assertEqual( d.EditableBody(), STX_NO_HEADERS )
+        self.failUnless( d.CookedBody() )
+        self.assertEqual( d.Format(), 'text/plain' )
     
     def test_STX_NoHeaders( self ):
         REQUEST=fakeRequest()
@@ -312,21 +315,21 @@
                        , description="Look, Ma, no headers!"
                        , subject=( "plain", "STX" )
                        )
-        assert d.Format() == 'text/html'
-        assert d.Title() == 'Plain STX'
-        assert d.Description() == 'Look, Ma, no headers!'
-        assert len( d.Subject() ) == 2
-        assert 'plain' in d.Subject()
-        assert 'STX' in d.Subject()
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Title(), 'Plain STX' )
+        self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
+        self.assertEqual( len( d.Subject() ), 2 )
+        self.failUnless( 'plain' in d.Subject() )
+        self.failUnless( 'STX' in d.Subject() )
 
         d.PUT(REQUEST, RESPONSE=fakeResponse())
         
-        assert d.Format() == 'text/plain'
-        assert d.Title() == 'Plain STX'
-        assert d.Description() == 'Look, Ma, no headers!'
-        assert len( d.Subject() ) == 2
-        assert 'plain' in d.Subject()
-        assert 'STX' in d.Subject()
+        self.assertEqual( d.Format(), 'text/plain' )
+        self.assertEqual( d.Title(), 'Plain STX' )
+        self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
+        self.assertEqual( len( d.Subject() ), 2 )
+        self.failUnless( 'plain' in d.Subject() )
+        self.failUnless( 'STX' in d.Subject() )
     
     def test_STX_NoHeaders_but_colon( self ):
         d = Document('foo')
@@ -390,14 +393,14 @@
                     get_headers.append( ( 'title', match.group(1) ) )
             get_lines = get_lines[1:]
 
-        assert get_lines == simple_lines
+        self.assertEqual( get_lines, simple_lines )
 
-        assert get_headers
-        assert simple_headers
-        assert len( get_headers ) >= len( simple_headers )
+        self.failUnless( get_headers )
+        self.failUnless( simple_headers )
+        self.failUnless( len( get_headers ) >= len( simple_headers ) )
 
         for header in simple_headers:
-            assert header in get_headers, [header, get_headers]
+            self.failUnless( header in get_headers )
 
     def testSTX( self ):
         REQUEST=fakeRequest()
@@ -419,10 +422,10 @@
             get_headers.append( get_lines[0] )
             get_lines = get_lines[1:]
 
-        assert get_lines == simple_lines
+        self.assertEqual( get_lines, simple_lines )
 
         for header in simple_headers:
-            assert header in get_headers, [header, get_headers]
+            self.failUnless( header in get_headers )
 
 class TestDocumentPUT(unittest.TestCase):
     def setUp(self):
@@ -446,9 +449,8 @@
         self._request.body = STX_WITH_HTML
 
         r = d.PUT(self._request, self._response)
-        assert d.Format() == 'text/plain', "%s != %s" % (
-            d.Format(), 'text/plain')
-        assert r.status == 204
+        self.assertEqual( d.Format(), 'text/plain' )
+        self.assertEqual( r.status, 204 )
 
     def test_PutStructuredText(self):
         d = Document('foo')
@@ -456,28 +458,25 @@
         self._request.body = BASIC_STRUCTUREDTEXT
 
         r = d.PUT(self._request, self._response)
-        assert d.Format() == 'text/plain', '%s != %s' % (
-            d.Format(), 'text/plain')
-        assert r.status == 204
+        self.assertEqual( d.Format(), 'text/plain' )
+        self.assertEqual( r.status, 204 )
 
     def test_PutHtmlWithDoctype(self):
         d = Document('foo')
         html = '%s\n\n  \n   %s' % (DOCTYPE, BASIC_HTML)
         self._request.body = html
         r = d.PUT(self._request, self._response)
-        assert d.Format() == 'text/html', "%s != %s" % (
-            d.Format(), 'text/html')
-        assert d.Description() == 'Describe me'
-        assert r.status == 204
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Description(), 'Describe me' )
+        self.assertEqual( r.status, 204 )
 
     def test_PutHtml(self):
         d = Document('foo')
         self._request.body = BASIC_HTML
         r = d.PUT(self._request, self._response)
-        assert d.Format() == 'text/html', "%s != %s" % (
-            d.Format(), 'text/html')
-        assert d.Description() == 'Describe me'
-        assert r.status == 204
+        self.assertEqual( d.Format(), 'text/html' )
+        self.assertEqual( d.Description(), 'Describe me' )
+        self.assertEqual( r.status, 204 )
 
 
 def test_suite():