Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
CMFDefault.tests.test_utils.DefaultUtilsTests Class Reference
Collaboration diagram for CMFDefault.tests.test_utils.DefaultUtilsTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_parseHeadersBody_no_body
def test_parseHeadersBody_continuation
def test_parseHeadersBody_embedded_blank_line
def test_parseHeadersBody_body
def test_parseHeadersBody_body_malformed_terminator
def test_parseHeadersBody_preload
def test_scrubHTML_no_adapter_falls_back
def test_scrubHTML_with_adapter
def test_bodyfinder
def test_html_headcheck
def test_tuplize
def test_seq_strip
def test_html_marshal
def test_toUnicode
def test_checkEmailAddress
def test_formatRFC822Headers_simple
def test_formatRFC822Headers_empty
def test_formatRFC822Headers_multiline
def test_formatRFC822Headers_multiline_trailing_blank_line
def test_formatRFC822Headers_multiline_intermediate_blank_line

Static Public Attributes

string COMMON_HEADERS
string MULTILINE_DESCRIPTION
 MULTIPARAGRAPH_DESCRIPTION = \
string TEST_BODY

Detailed Description

Definition at line 28 of file test_utils.py.


Member Function Documentation

Definition at line 187 of file test_utils.py.

00187 
00188     def test_bodyfinder(self):
00189         from Products.CMFDefault.utils import bodyfinder
00190 
00191         self.assertEqual( bodyfinder(FAUX_HTML_LEADING_TEXT),
00192                           '\n  <h1>Not a lot here</h1>\n ' )
00193         self.assertEqual( bodyfinder(SIMPLE_HTML),
00194                           '\n  <h1>Not a lot here</h1>\n ' )
00195         self.assertEqual( bodyfinder(SIMPLE_STRUCTUREDTEXT),
00196                           SIMPLE_STRUCTUREDTEXT )
00197         self.assertEqual( bodyfinder(SIMPLE_XHTML),
00198                           '\n  <h1>Not a lot here</h1>\n ' )
00199         self.assertEqual( bodyfinder(STX_WITH_HTML),
00200                           '<p>Hello world, I am Bruce.</p>' )

Here is the call graph for this function:

Definition at line 246 of file test_utils.py.

00246 
00247     def test_checkEmailAddress(self):
00248         from Products.CMFDefault.exceptions import EmailAddressInvalid
00249         from Products.CMFDefault.utils import checkEmailAddress
00250 
00251         self.assertEqual(checkEmailAddress('foo@example.com'), None)
00252         self.assertEqual(checkEmailAddress('foo@1bar.example.com'), None)
00253         self.assertEqual(checkEmailAddress('foo@123456.com'), None)
00254         self.assertEqual(checkEmailAddress('$.-@example.com'), None)
00255         self.assertEqual(checkEmailAddress(u'foo@example.com'), None)
00256         # CMF Collector issue #322
00257         self.assertEqual(checkEmailAddress('user+site@example.com'), None)
00258         # CMF Collector issue #326
00259         self.assertEqual(checkEmailAddress('username_@example.com'), None)
00260         # CMF Collector issue #401
00261         self.assertEqual(checkEmailAddress("user'site@example.com"), None)
00262         # CMF Collector issue #495
00263         self.assertEqual(checkEmailAddress("user@a.example.com"), None)
00264         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00265                           'this is not an e-mail address')
00266         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00267                           'foo@example.com, bar@example.com')
00268         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00269                           'foo.@example.com')
00270         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00271                           '.foo@example.com')
00272         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00273                           'foo@-bar.example.com')
00274         # RFC 2821 local-part: max 64 characters
00275         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00276                           'f'*63+'oo@example.com')
00277         # RFC 2821 domain: max 255 characters
00278         self.assertRaises(EmailAddressInvalid, checkEmailAddress,
00279                           'foo@'+'b'*242+'ar.example.com')

Definition at line 291 of file test_utils.py.

00291 
00292     def test_formatRFC822Headers_empty(self):
00293         from Products.CMFDefault.utils import formatRFC822Headers
00294 
00295         HEADERS = [ ('Foo', 'foo')
00296                   , ('Bar', '')
00297                   ]
00298 
00299         formatted = formatRFC822Headers( HEADERS )
00300 
00301         self.assertEqual( formatted, 'Foo: foo\r\nBar: ' )

Here is the call graph for this function:

Definition at line 302 of file test_utils.py.

00302 
00303     def test_formatRFC822Headers_multiline(self):
00304         from Products.CMFDefault.utils import formatRFC822Headers
00305 
00306         HEADERS = [ ('Foo', 'foo')
00307                   , ('Bar', 'bar\nwith multiline')
00308                   ]
00309 
00310         formatted = formatRFC822Headers( HEADERS )
00311 
00312         self.assertEqual( formatted
00313                         , 'Foo: foo\r\nBar: bar\r\n  with multiline' )

Here is the call graph for this function:

Definition at line 326 of file test_utils.py.

00326 
00327     def test_formatRFC822Headers_multiline_intermediate_blank_line(self):
00328         from Products.CMFDefault.utils import formatRFC822Headers
00329 
00330         HEADERS = [ ('Foo', 'foo')
00331                   , ('Bar', 'bar\n\nwith multiline')
00332                   ]
00333 
00334         formatted = formatRFC822Headers( HEADERS )
00335 
00336         self.assertEqual( formatted
00337                         , 'Foo: foo\r\nBar: bar\r\n  \r\n  with multiline' )
00338 

Here is the call graph for this function:

Definition at line 314 of file test_utils.py.

00314 
00315     def test_formatRFC822Headers_multiline_trailing_blank_line(self):
00316         from Products.CMFDefault.utils import formatRFC822Headers
00317 
00318         HEADERS = [ ('Foo', 'foo')
00319                   , ('Bar', 'bar\nwith multiline\n')
00320                   ]
00321 
00322         formatted = formatRFC822Headers( HEADERS )
00323 
00324         self.assertEqual( formatted
00325                         , 'Foo: foo\r\nBar: bar\r\n  with multiline' )

Here is the call graph for this function:

Definition at line 280 of file test_utils.py.

00280 
00281     def test_formatRFC822Headers_simple(self):
00282         from Products.CMFDefault.utils import formatRFC822Headers
00283 
00284         HEADERS = [ ('Foo', 'foo')
00285                   , ('Bar', 'bar')
00286                   ]
00287 
00288         formatted = formatRFC822Headers( HEADERS )
00289 
00290         self.assertEqual( formatted, 'Foo: foo\r\nBar: bar' )

Here is the call graph for this function:

Definition at line 201 of file test_utils.py.

00201 
00202     def test_html_headcheck(self):
00203         from Products.CMFDefault.utils import html_headcheck
00204 
00205         self.assertEqual( html_headcheck(FAUX_HTML_LEADING_TEXT), 0 )
00206         self.assertEqual( html_headcheck(SIMPLE_HTML), 1 )
00207         self.assertEqual( html_headcheck(SIMPLE_STRUCTUREDTEXT), 0 )
00208         self.assertEqual( html_headcheck(SIMPLE_XHTML), 1 )
00209         self.assertEqual( html_headcheck(STX_WITH_HTML), 0 )

Here is the call graph for this function:

Definition at line 230 of file test_utils.py.

00230 
00231     def test_html_marshal(self):
00232         from Products.CMFDefault.utils import html_marshal
00233 
00234         self.assertEqual( html_marshal(foo=1), ( ('foo:int', 1), ) )
00235         self.assertEqual( html_marshal(foo=1, bar='baz >&baz'),
00236                           ( ('foo:int', 1), ('bar', 'baz >&baz') ) )

Here is the call graph for this function:

Definition at line 88 of file test_utils.py.

00088 
00089     def test_parseHeadersBody_body( self ):
00090         from Products.CMFDefault.utils import parseHeadersBody
00091 
00092         headers, body = parseHeadersBody( '%s\n\n%s'
00093                                         % ( self.COMMON_HEADERS
00094                                           , self.TEST_BODY
00095                                           )
00096                                         )
00097         self.assertEqual( len( headers ), 2 )
00098         self.assertEqual( body, self.TEST_BODY )

Here is the call graph for this function:

Definition at line 99 of file test_utils.py.

00099 
00100     def test_parseHeadersBody_body_malformed_terminator( self ):
00101         from Products.CMFDefault.utils import parseHeadersBody
00102 
00103         headers, body = parseHeadersBody( '%s\n \n%s'
00104                                         % ( self.COMMON_HEADERS
00105                                           , self.TEST_BODY
00106                                           )
00107                                         )
00108         self.assertEqual( len( headers ), 2 )
00109         self.assertEqual( body, self.TEST_BODY )

Here is the call graph for this function:

Definition at line 57 of file test_utils.py.

00057 
00058     def test_parseHeadersBody_continuation( self ):
00059         from Products.CMFDefault.utils import parseHeadersBody
00060 
00061         headers, body = parseHeadersBody( '%s\n%s\n\n'
00062                                         % ( self.COMMON_HEADERS
00063                                           , self.MULTILINE_DESCRIPTION
00064                                           )
00065                                         )
00066         self.assertEqual( len( headers ), 3 )
00067         self.failUnless( 'Description' in headers.keys() )
00068         desc_len = len( headers[ 'Description' ].split('\n') )
00069         self.assertEqual( desc_len, 2 )
00070         self.assertEqual( len( body ), 0 )

Here is the call graph for this function:

Definition at line 71 of file test_utils.py.

00071 
00072     def test_parseHeadersBody_embedded_blank_line( self ):
00073         from Products.CMFDefault.utils import parseHeadersBody
00074 
00075         headers, body = parseHeadersBody( '%s\n%s\n\n%s'
00076                                         % ( self.COMMON_HEADERS
00077                                           , self.MULTIPARAGRAPH_DESCRIPTION
00078                                           , self.TEST_BODY
00079                                           )
00080                                         )
00081         self.assertEqual( len( headers ), 3 )
00082         self.failUnless( 'Description' in headers.keys() )
00083         desc_lines = headers[ 'Description' ].split('\n')
00084         desc_len = len( desc_lines )
00085         self.assertEqual( desc_len, 3, desc_lines )
00086         self.assertEqual( desc_lines[1], ' ' )
00087         self.assertEqual( body, self.TEST_BODY )

Here is the call graph for this function:

Definition at line 47 of file test_utils.py.

00047 
00048     def test_parseHeadersBody_no_body( self ):
00049         from Products.CMFDefault.utils import parseHeadersBody
00050 
00051         headers, body = parseHeadersBody( '%s\n\n' % self.COMMON_HEADERS )
00052         self.assertEqual( len( headers ), 2 )
00053         self.failUnless( 'Author' in headers.keys() )
00054         self.assertEqual( headers[ 'Author' ], 'Tres Seaver' )
00055         self.failUnless( 'Title' in headers.keys() )
00056         self.assertEqual( len( body ), 0 )

Here is the call graph for this function:

Definition at line 110 of file test_utils.py.

00110 
00111     def test_parseHeadersBody_preload( self ):
00112         from Products.CMFDefault.utils import parseHeadersBody
00113 
00114         preloaded = { 'Author' : 'xxx', 'text_format' : 'structured_text' }
00115         headers, body = parseHeadersBody( '%s\n%s\n\n%s'
00116                                         % ( self.COMMON_HEADERS
00117                                           , self.MULTILINE_DESCRIPTION
00118                                           , self.TEST_BODY
00119                                           )
00120                                         , preloaded
00121                                         )
00122         self.assertEqual( len( headers ), 4 )
00123         self.assertNotEqual( preloaded[ 'Author' ], headers[ 'Author' ] )
00124         self.assertEqual( preloaded[ 'text_format' ], headers[ 'text_format' ] )

Here is the call graph for this function:

Definition at line 125 of file test_utils.py.

00125 
00126     def test_scrubHTML_no_adapter_falls_back(self):
00127         from Products.CMFDefault.utils import scrubHTML
00128 
00129         self.assertEqual( scrubHTML('<a href="foo.html">bar</a>'),
00130                           '<a href="foo.html">bar</a>' )
00131         self.assertEqual( scrubHTML('<b>bar</b>'),
00132                           '<b>bar</b>' )
00133         self.assertEqual( scrubHTML('<base href="" /><base>'),
00134                           '<base href="" /><base />' )
00135         self.assertEqual( scrubHTML('<blockquote>bar</blockquote>'),
00136                           '<blockquote>bar</blockquote>' )
00137         self.assertEqual( scrubHTML('<body bgcolor="#ffffff">bar</body>'),
00138                           '<body bgcolor="#ffffff">bar</body>' )
00139         self.assertEqual( scrubHTML('<br /><br>'),
00140                           '<br /><br />' )
00141         self.assertEqual( scrubHTML('<hr /><hr>'),
00142                           '<hr /><hr />' )
00143         self.assertEqual( scrubHTML('<img src="foo.png" /><img>'),
00144                           '<img src="foo.png" /><img />' )
00145         self.assertEqual( scrubHTML('<meta name="title" content="" /><meta>'),
00146                           '<meta name="title" content="" /><meta />' )

Here is the call graph for this function:

Definition at line 147 of file test_utils.py.

00147 
00148     def test_scrubHTML_with_adapter(self):
00149         from zope.interface import implements
00150         from zope.component.testing import setUp
00151         from zope.component.testing import tearDown
00152         from zope.app.testing import ztapi
00153         from Products.CMFDefault.interfaces import IHTMLScrubber
00154         from Products.CMFDefault.utils import scrubHTML
00155 
00156         class _Scrubber:
00157             implements(IHTMLScrubber)
00158             def scrub(self, html):
00159                 return html.upper()
00160 
00161 
00162         setUp()
00163         try:
00164             ztapi.provideUtility(IHTMLScrubber, _Scrubber())
00165             self.assertEqual( scrubHTML('<a href="foo.html">bar</a>'),
00166                             '<A HREF="FOO.HTML">BAR</A>' )
00167             self.assertEqual( scrubHTML('<b>bar</b>'),
00168                             '<B>BAR</B>' )
00169             self.assertEqual( scrubHTML('<base href="" /><base>'),
00170                             '<BASE HREF="" /><BASE>' )
00171             self.assertEqual( scrubHTML('<blockquote>bar</blockquote>'),
00172                             '<BLOCKQUOTE>BAR</BLOCKQUOTE>' )
00173             self.assertEqual( scrubHTML('<body bgcolor="#ffffff">bar</body>'),
00174                             '<BODY BGCOLOR="#FFFFFF">BAR</BODY>' )
00175             self.assertEqual( scrubHTML('<br /><br>'),
00176                             '<BR /><BR>' )
00177             self.assertEqual( scrubHTML('<hr /><hr>'),
00178                             '<HR /><HR>' )
00179             self.assertEqual( scrubHTML('<img src="foo.png" /><img>'),
00180                             '<IMG SRC="FOO.PNG" /><IMG>' )
00181             self.assertEqual( scrubHTML(
00182                                 '<meta name="title" content="" /><meta>'),
00183                             '<META NAME="TITLE" CONTENT="" /><META>' )
00184 
00185         finally:
00186             tearDown()

Here is the call graph for this function:

Definition at line 222 of file test_utils.py.

00222 
00223     def test_seq_strip(self):
00224         from Products.CMFDefault.utils import seq_strip
00225 
00226         self.assertEqual( seq_strip(['one ', ' two', ' three ']),
00227                           ['one','two','three'] )
00228         self.assertEqual( seq_strip(('one ', ' two', ' three ')),
00229                           ('one','two','three') )

Here is the call graph for this function:

Definition at line 237 of file test_utils.py.

00237 
00238     def test_toUnicode(self):
00239         from Products.CMFDefault.utils import toUnicode
00240 
00241         self.assertEqual( toUnicode('foo'), u'foo' )
00242         self.assertEqual( toUnicode( ('foo', 'bar'), 'ascii' ),
00243                           (u'foo', u'bar') )
00244         self.assertEqual( toUnicode( {'foo': 'bar'}, 'iso-8859-1' ),
00245                           {'foo': u'bar'} )

Here is the call graph for this function:

Definition at line 210 of file test_utils.py.

00210 
00211     def test_tuplize(self):
00212         from Products.CMFDefault.utils import comma_split
00213         from Products.CMFDefault.utils import tuplize
00214         wanted = ('one','two','three')
00215 
00216         self.assertEqual( tuplize('string', 'one two three'), wanted )
00217         self.assertEqual( tuplize('unicode', u'one two three'), wanted )
00218         self.assertEqual( tuplize('string', 'one,two,three', comma_split),
00219                           wanted )
00220         self.assertEqual( tuplize('list', ['one',' two','three ']), wanted )
00221         self.assertEqual( tuplize('tuple', ('one','two','three')), wanted )

Here is the call graph for this function:


Member Data Documentation

Initial value:
'''Author: Tres Seaver
Title: Test Products.CMFDefault.utils.parseHeadersBody'''

Definition at line 30 of file test_utils.py.

Initial value:
'''Description: this description spans
    multiple lines.'''

Definition at line 33 of file test_utils.py.

Definition at line 36 of file test_utils.py.

Initial value:
'''Body goes here, and can span multiple
lines.  It can even include "headerish" lines, like:

Header: value
'''

Definition at line 41 of file test_utils.py.


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