Back to index

plone3  3.1.7
Public Member Functions
CMFDefault.tests.test_Document.DocumentTests Class Reference
Inheritance diagram for CMFDefault.tests.test_Document.DocumentTests:
Inheritance graph
[legend]
Collaboration diagram for CMFDefault.tests.test_Document.DocumentTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_z2interfaces
def test_z3interfaces
def test_Empty
def test_editBasicHTML
def test_editSimpleXHTML
def test_UpperedHtml
def test_EntityInTitle
def test_HtmlWithDoctype
def test_HtmlWithoutNewlines
def test_EditPlainDocumentWithEmbeddedHTML
def test_BigHtml
def test_BigHtml_via_upload
def test_Htmltag_removal_and_formatchange
def test_Html_Fragment
def test_plain_text
def test_EditStructuredTextWithHTML
def test_StructuredText
def test_STX_Levels
def test_Init
def test_STX_NoHeaders
def test_STX_NoHeaders_but_colon
def test_ZMI_edit
def test_Format_methods
def test_default_format

Detailed Description

Definition at line 62 of file test_Document.py.


Member Function Documentation

Definition at line 153 of file test_Document.py.

00153 
00154     def test_BigHtml(self):
00155         d = self._makeOne('foo')
00156         s = []
00157         looper = '<li> number %s</li>'
00158         for i in range(12000): s.append(looper % i)
00159         body = '<ul>\n%s\n</ul>' % '\n'.join(s)
00160         self.REQUEST['BODY'] = HTML_TEMPLATE % {'title': 'big document',
00161                                 'body': body}
00162         d.PUT(self.REQUEST, self.RESPONSE)
00163         self.assertEqual( d.CookedBody(), body )

Definition at line 164 of file test_Document.py.

00164 
00165     def test_BigHtml_via_upload(self):
00166         d = self._makeOne('foo')
00167         s = []
00168         looper = '<li> number %s</li>'
00169         for i in range(12000): s.append(looper % i)
00170         body = '<ul>\n%s\n</ul>' % '\n'.join(s)
00171         html = HTML_TEMPLATE % {'title': 'big document',
00172                                 'body': body}
00173         _file = StringIO( html )
00174         d.edit(text_format='html', text='', file=_file)
00175         self.assertEqual( d.CookedBody(), body )

Definition at line 368 of file test_Document.py.

00368 
00369     def test_default_format( self ):
00370         d = self._makeOne('foo', text='')
00371 
00372         self.assertEqual( d.Format(), 'text/plain' )
00373         self.assertEqual( d.text_format, 'structured-text' )
00374 

Definition at line 90 of file test_Document.py.

00090 
00091     def test_editBasicHTML(self):
00092         d = self._makeOne('foo')
00093         d.edit('html', BASIC_HTML)
00094 
00095         self.failUnless( hasattr(d, 'cooked_text') )
00096         self.assertEqual( d.Format(), 'text/html' )
00097         self.assertEqual( d.text.find('</body>'), -1 )
00098         self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ' )
00099 
00100         # Since the format is html, the STX level operands should
00101         # have no effect.
00102         ct = d.CookedBody(stx_level=3, setlevel=1)
00103         self.assertEqual( d._stx_level, 1 )

Definition at line 145 of file test_Document.py.

00145 
00146     def test_EditPlainDocumentWithEmbeddedHTML(self):
00147         d = self._makeOne('foo')
00148         d.edit('structured-text', FAUX_HTML_LEADING_TEXT)
00149         fully_edited = d.cooked_text
00150         d._edit(FAUX_HTML_LEADING_TEXT)
00151         partly_edited = d.cooked_text
00152         self.assertEquals(fully_edited, partly_edited)

Definition at line 104 of file test_Document.py.

00104 
00105     def test_editSimpleXHTML(self):
00106         d = self._makeOne('foo')
00107         d.edit('html', SIMPLE_XHTML)
00108 
00109         self.failUnless( hasattr(d, 'cooked_text') )
00110         self.assertEqual( d.Format(), 'text/html' )
00111         self.assertEqual( d.cooked_text, '\n  <h1>Not a lot here</h1>\n ')

Definition at line 212 of file test_Document.py.

00212 
00213     def test_EditStructuredTextWithHTML(self):
00214         d = self._makeOne('foo')
00215         d.edit(text_format='structured-text', text=STX_WITH_HTML)
00216 
00217         self.assertEqual( d.Format(), 'text/plain' )
00218         self.assertEqual( d.get_size(), len(STX_WITH_HTML) )

Definition at line 80 of file test_Document.py.

00080 
00081     def test_Empty(self):
00082         d = self._makeOne('foo', text_format='structured-text')
00083 
00084         self.assertEqual( d.title, '' )
00085         self.assertEqual( d.description, '' )
00086         self.assertEqual( d.text, '' )
00087         self.assertEqual( d.text_format, 'structured-text' )
00088         self.assertEqual( d._stx_level, 1 )
00089         self.assertEqual( d.get_size(), 0 )

Definition at line 123 of file test_Document.py.

00123 
00124     def test_EntityInTitle(self):
00125         self.REQUEST['BODY'] = ENTITY_IN_TITLE
00126         d = self._makeOne('foo')
00127         d.PUT(self.REQUEST, self.RESPONSE)
00128 
00129         self.assertEqual( d.title, '&Auuml;rger' )

Definition at line 345 of file test_Document.py.

00345 
00346     def test_Format_methods(self):
00347         d = self._makeOne('foo')
00348         d.setFormat('plain')
00349         self.assertEqual( d.text_format, 'plain' )
00350         self.assertEqual( d.Format(), 'text/plain' )
00351         d.setFormat( d.Format() )
00352         self.assertEqual( d.text_format, 'plain' )
00353 
00354         d.setFormat('structured-text')
00355         self.assertEqual( d.text_format, 'structured-text' )
00356         self.assertEqual( d.Format(), 'text/plain' )
00357         d.setFormat( d.Format() )
00358         self.assertEqual( d.text_format, 'structured-text' )
00359 
00360         d.setFormat('html')
00361         self.assertEqual( d.text_format, 'html' )
00362         self.assertEqual( d.Format(), 'text/html' )
00363         d.setFormat( d.Format() )
00364         self.assertEqual( d.text_format, 'html' )
00365 
00366         d.setFormat('foo')
00367         self.assertEqual( d.text_format, 'structured-text' )

Definition at line 195 of file test_Document.py.

00195 
00196     def test_Html_Fragment(self):
00197         # Test that edits with HTML fragments behave nicely
00198         FRAGMENT = '<div id="placeholder">CONTENT</div>'
00199         d = self._makeOne('foo')
00200         d.edit(text_format='html', text=FRAGMENT)
00201         self.assertEqual( d.CookedBody(), FRAGMENT )
00202         self.assertEqual( d.get_size(), len(FRAGMENT) )

Definition at line 176 of file test_Document.py.

00176 
00177     def test_Htmltag_removal_and_formatchange(self):
00178         # Test for http://www.zope.org/Collectors/CMF/214
00179         d = self._makeOne('foo')
00180         quoted_html = html_quote(BASIC_HTML)
00181 
00182         # Put HTML into a plain text document
00183         d.edit(text_format='plain', text=BASIC_HTML)
00184         new_body = d.CookedBody()
00185         self.failIf(new_body==BASIC_HTML)
00186         self.failUnless(new_body.startswith(quoted_html[:5]))
00187 
00188         # Now we change the format. The body *must* change because
00189         # the format change will trigger re-cooking
00190         old_body = d.CookedBody()
00191         d.setFormat('html')
00192         new_body = d.CookedBody()
00193         self.failIf(old_body==new_body)
00194         self.failIf(new_body==BASIC_HTML)

Definition at line 130 of file test_Document.py.

00130 
00131     def test_HtmlWithDoctype(self):
00132         self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
00133         d = self._makeOne('foo')
00134         d.PUT(self.REQUEST, self.RESPONSE)
00135 
00136         self.assertEqual( d.Description(), 'Describe me' )

Definition at line 137 of file test_Document.py.

00137 
00138     def test_HtmlWithoutNewlines(self):
00139         self.REQUEST['BODY'] = ''.join((BASIC_HTML.split('\n')))
00140         d = self._makeOne('foo')
00141         d.PUT(self.REQUEST, self.RESPONSE)
00142 
00143         self.assertEqual( d.Format(), 'text/html' )
00144         self.assertEqual( d.Description(), 'Describe me' )

Definition at line 270 of file test_Document.py.

00270 
00271     def test_Init(self):
00272         self.REQUEST['BODY']=BASIC_STRUCTUREDTEXT
00273         d = self._makeOne('foo')
00274         d.PUT(self.REQUEST, self.RESPONSE)
00275         self.assertEqual( d.Format(), 'text/plain' )
00276         self.assertEqual( d.Title(), 'My Document' )
00277         self.assertEqual( d.Description(), 'A document by me' )
00278         self.assertEqual( len(d.Contributors()), 3 )
00279         self.failUnless( d.cooked_text.find('<p>') >= 0 )
00280 
00281         d = self._makeOne('foo', text='')
00282         self.REQUEST['BODY']=BASIC_HTML
00283         d.PUT(self.REQUEST, self.RESPONSE)
00284         self.assertEqual( d.Format(), 'text/html' )
00285         self.assertEqual( d.Title(), 'Title in tag' )
00286         self.assertEqual( len(d.Contributors()), 3 )
00287 
00288         d = self._makeOne('foo', text_format='structured-text',
00289                           title='Foodoc')
00290         self.assertEqual( d.text, '' )
00291         self.failIf( d.CookedBody() )
00292         self.assertEqual( d.title, 'Foodoc' )
00293         self.assertEqual( d.Format(), 'text/plain' )
00294 
00295         # Tracker issue 435:  initial text is not cooked.
00296         d = self._makeOne('foo', text_format='structured-text',
00297                           text=STX_NO_HEADERS)
00298         self.assertEqual( d.EditableBody(), STX_NO_HEADERS )
00299         self.failUnless( d.CookedBody() )
00300         self.assertEqual( d.Format(), 'text/plain' )

Definition at line 203 of file test_Document.py.

00203 
00204     def test_plain_text(self):
00205         # test that plain text forrmat works
00206         PLAIN_TEXT = '*some plain text*\nwith a newline'
00207         d = self._makeOne('foo')
00208         d.edit(text_format='plain', text=PLAIN_TEXT)
00209         self.assertEqual( d.CookedBody(),
00210                           '*some plain text*<br />with a newline')
00211         self.assertEqual( d.get_size(), len(PLAIN_TEXT) )

Definition at line 219 of file test_Document.py.

00219 
00220     def test_StructuredText(self):
00221         self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
00222         d = self._makeOne('foo')
00223         d.PUT(self.REQUEST, self.RESPONSE)
00224 
00225         self.failUnless( hasattr(d, 'cooked_text') )
00226         self.assertEqual( d.Format(), 'text/plain' )
00227         self.assertEqual( d.Title(), 'My Document' )
00228         self.assertEqual( d.Description(), 'A document by me' )
00229         self.assertEqual( len(d.Contributors()), 3 )
00230         self.failUnless( d.cooked_text.find('<p>') >= 0 )
00231         self.failUnless( d.CookedBody().find('<h1') >= 0 )
00232 
00233         # Make sure extra HTML is NOT found
00234         self.failUnless( d.cooked_text.find('<title>') < 0 )
00235         self.failUnless( d.cooked_text.find('<body>') < 0 )
00236 
00237         # test subject/keyword headers
00238         subj = list(d.Subject())
00239         self.assertEqual( len(subj), 4 )
00240         subj.sort()
00241         self.assertEqual( subj, [ 'content management'
00242                                 , 'framework'
00243                                 , 'unit tests'
00244                                 , 'zope'
00245                                 ] )

Definition at line 246 of file test_Document.py.

00246 
00247     def test_STX_Levels(self):
00248         d = self._makeOne('foo')
00249         d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)
00250         self.assertEqual( d._stx_level, 1 )
00251 
00252         ct = d.CookedBody()
00253         self.failUnless( d.CookedBody().find('<h1') >= 0 )
00254         self.assertEqual( d._stx_level, 1 )
00255 
00256         ct = d.CookedBody(stx_level=2)
00257         self.failIf( ct.find('<h1') >= 0 )
00258         self.failUnless( ct.find('<h2') >= 0 )
00259         self.assertEqual( d._stx_level, 1 )
00260 
00261         ct = d.CookedBody(stx_level=2, setlevel=1)
00262         self.failIf( ct.find('<h1') >= 0 )
00263         self.failUnless( ct.find('<h2') >= 0 )
00264         self.assertEqual( d._stx_level, 2 )
00265 
00266         ct = d.CookedBody()
00267         self.assertEqual( d._stx_level, 2 )
00268         self.failIf( d.CookedBody().find('<h1') >= 0 )
00269         self.failUnless( d.CookedBody().find('<h2') >= 0 )

Definition at line 301 of file test_Document.py.

00301 
00302     def test_STX_NoHeaders( self ):
00303         self.REQUEST['BODY']=STX_NO_HEADERS
00304         d = self._makeOne('foo')
00305         d.editMetadata( title="Plain STX"
00306                        , description="Look, Ma, no headers!"
00307                        , subject=( "plain", "STX" )
00308                        )
00309         self.assertEqual( d.Format(), 'text/html' )
00310         self.assertEqual( d.Title(), 'Plain STX' )
00311         self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
00312         self.assertEqual( len( d.Subject() ), 2 )
00313         self.failUnless( 'plain' in d.Subject() )
00314         self.failUnless( 'STX' in d.Subject() )
00315 
00316         d.PUT(self.REQUEST, self.RESPONSE)
00317 
00318         self.assertEqual( d.Format(), 'text/plain' )
00319         self.assertEqual( d.Title(), 'Plain STX' )
00320         self.assertEqual( d.Description(), 'Look, Ma, no headers!' )
00321         self.assertEqual( len( d.Subject() ), 2 )
00322         self.failUnless( 'plain' in d.Subject() )
00323         self.failUnless( 'STX' in d.Subject() )

Definition at line 324 of file test_Document.py.

00324 
00325     def test_STX_NoHeaders_but_colon( self ):
00326         d = self._makeOne('foo')
00327         d.editMetadata( title="Plain STX"
00328                        , description="Look, Ma, no headers!"
00329                        , subject=( "plain", "STX" )
00330                        )
00331 
00332         d.edit(text_format='structured-text', text=STX_NO_HEADERS_BUT_COLON)
00333         self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )

Definition at line 112 of file test_Document.py.

00112 
00113     def test_UpperedHtml(self):
00114         self.REQUEST['BODY'] = BASIC_HTML.upper()
00115         d = self._makeOne('foo')
00116         d.PUT(self.REQUEST, self.RESPONSE)
00117 
00118         self.assertEqual( d.Format(), 'text/html' )
00119         self.assertEqual( d.title, 'TITLE IN TAG' )
00120         self.assertEqual( d.text.find('</BODY'), -1 )
00121         self.assertEqual( d.Description(), 'DESCRIBE ME' )
00122         self.assertEqual( len(d.Contributors()), 3 )

Definition at line 64 of file test_Document.py.

00064 
00065     def test_z2interfaces(self):
00066         from Interface.Verify import verifyClass
00067         from Products.CMFDefault.interfaces.Document import IDocument
00068         from Products.CMFDefault.interfaces.Document import IMutableDocument
00069 
00070         verifyClass(IDocument, self._getTargetClass())
00071         verifyClass(IMutableDocument, self._getTargetClass())

Here is the call graph for this function:

Definition at line 72 of file test_Document.py.

00072 
00073     def test_z3interfaces(self):
00074         from zope.interface.verify import verifyClass
00075         from Products.CMFDefault.interfaces import IDocument
00076         from Products.CMFDefault.interfaces import IMutableDocument
00077 
00078         verifyClass(IDocument, self._getTargetClass())
00079         verifyClass(IMutableDocument, self._getTargetClass())

Here is the call graph for this function:

Definition at line 334 of file test_Document.py.

00334 
00335     def test_ZMI_edit( self ):
00336         d = self._makeOne('foo')
00337         d.editMetadata( title="Plain STX"
00338                        , description="Look, Ma, no headers!"
00339                        , subject=( "plain", "STX" )
00340                        )
00341 
00342         d.manage_editDocument( text_format='structured-text'
00343                              , text=STX_NO_HEADERS_BUT_COLON)
00344         self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )


The documentation for this class was generated from the following file: