[CMF-checkins] CVS: Products/CMFDefault/tests - test_Document.py:1.20.14.1 test_Link.py:1.2.20.1

Tres Seaver tseaver@zope.com
Tue, 8 Jan 2002 13:19:46 -0500


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

Modified Files:
      Tag: tseaver-tracker_407-branch
	test_Document.py test_Link.py 
Log Message:


  - Clean up emission of RFC822-style headers (Tracker #407):

    o Headers must be terminated with CRLF;

    o Header values with embedded newlines must pad continuation lines
      with leading whitespace).

  - Refactor test_Link to use 'assertEquals'.


=== Products/CMFDefault/tests/test_Document.py 1.20 => 1.20.14.1 ===
         d.PUT(REQUEST, RESPONSE=fakeResponse())
 
-        simple_lines = string.split( SIMPLE_HTML, '\n' )
-        get_lines = string.split( d.manage_FTPget(), '\n' )
+        rnlinesplit = re.compile( r'\r?\n?' )
+        simple_lines = rnlinesplit.split( SIMPLE_HTML )
+        get_lines = rnlinesplit.split( d.manage_FTPget() )
 
         # strip off headers
         meta_pattern = re.compile( r'meta name="([a-z]*)" '
@@ -408,8 +409,11 @@
         d = Document( 'foo' )
         d.PUT(REQUEST, RESPONSE=fakeResponse())
 
-        simple_lines = string.split( SIMPLE_STRUCTUREDTEXT, '\n' )
-        get_lines = string.split( d.manage_FTPget(), '\n' )
+        rnlinesplit = re.compile( r'\r?\n?' )
+
+        get_text = d.manage_FTPget()
+        simple_lines = rnlinesplit.split( SIMPLE_STRUCTUREDTEXT )
+        get_lines = rnlinesplit.split( get_text )
 
         # strip off headers
         simple_headers = []


=== Products/CMFDefault/tests/test_Link.py 1.2 => 1.2.20.1 ===
+import unittest, string, re
 from Products.CMFDefault.Link import Link
 
 BASIC_STRUCTUREDTEXT = '''\
@@ -9,42 +9,60 @@
 http://www.zope.org
 '''
 
-class LinkTests(unittest.TestCase):
+STX_W_CONTINUATION = '''\
+Title: Zope Community
+Description: Link to the Zope Community website,
+  including hundreds of contributed Zope products.
+Subject: open source; Zope; community
 
-    def setUp( self ):
-        get_transaction().begin()
+http://www.zope.org
+'''
 
-    def tearDown( self ):
-        get_transaction().abort()
+class LinkTests(unittest.TestCase):
 
     def test_Empty( self ):
         d = Link( 'foo' )
-        self.failUnless( d.Title() == '' )
-        self.failUnless( d.Description() == '' )
-        self.failUnless( d.getRemoteUrl() == '' )
+        self.assertEqual( d.Title(), '' )
+        self.assertEqual( d.Description(), '' )
+        self.assertEqual( d.getRemoteUrl(), '' )
 
     def test_StructuredText( self ):
         d = Link('foo')
         d._writeFromPUT( body=BASIC_STRUCTUREDTEXT )
         
-        self.failUnless( d.Title() == 'Zope Community' )
-        self.failUnless(
-                d.Description() == 'Link to the Zope Community website.' )
-        self.failUnless( len(d.Subject()) == 3 )
-        self.failUnless( d.getRemoteUrl() == 'http://www.zope.org' )
+        self.assertEqual( d.Title(), 'Zope Community' )
+        self.assertEqual( d.Description()
+                        , 'Link to the Zope Community website.' )
+        self.assertEqual( len(d.Subject()), 3 )
+        self.assertEqual( d.getRemoteUrl(), 'http://www.zope.org' )
+
+    def test_StructuredText_w_Continuation( self ):
+
+        d = Link('foo')
+        d._writeFromPUT( body=STX_W_CONTINUATION )
+        rnlinesplit = re.compile( r'\r?\n?' )
+        desc_lines = rnlinesplit.split( d.Description() )
+        
+        self.assertEqual( d.Title(), 'Zope Community' )
+        self.assertEqual( desc_lines[0]
+                        , 'Link to the Zope Community website,' )
+        self.assertEqual( desc_lines[1]
+                        , 'including hundreds of contributed Zope products.' )
+        self.assertEqual( len(d.Subject()), 3 )
+        self.assertEqual( d.getRemoteUrl(), 'http://www.zope.org' )
 
     def test_fixupMissingScheme( self ):
         d = Link( 'foo' )
         d.edit( 'http://foo.com' )
-        self.failUnless( d.getRemoteUrl() == 'http://foo.com' )
+        self.assertEqual( d.getRemoteUrl(), 'http://foo.com' )
 
         d = Link( 'bar' )
         d.edit( '//bar.com' )
-        self.failUnless( d.getRemoteUrl() == 'http://bar.com' )
+        self.assertEqual( d.getRemoteUrl(), 'http://bar.com' )
 
         d = Link( 'baz' )
         d.edit( 'baz.com' )
-        self.failUnless( d.getRemoteUrl() == 'http://baz.com' )
+        self.assertEqual( d.getRemoteUrl(), 'http://baz.com' )