[CMF-checkins] CVS: CMF/CMFDefault/tests - test_Document.py:1.21.8.1 utils.py:NONE
Chris Withers
chrisw@nipltd.com
Fri, 15 Feb 2002 13:20:23 -0500
Update of /cvs-repository/CMF/CMFDefault/tests
In directory cvs.zope.org:/tmp/cvs-serv21980/CMFDefault/tests
Modified Files:
Tag: ChrisW-refactor_tests-branch
test_Document.py
Removed Files:
Tag: ChrisW-refactor_tests-branch
utils.py
Log Message:
Done Document
=== CMF/CMFDefault/tests/test_Document.py 1.21 => 1.21.8.1 ===
-from Products.CMFDefault.tests.utils import fakeRequest, fakeResponse
+from unittest import TestSuite, makeSuite, main
+from StringIO import StringIO
+from re import compile
+
+from Products.CMFCore.tests.base.testcase import \
+ RequestTest
+
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">'''
HTML_TEMPLATE = '''\
@@ -119,13 +124,11 @@
it shouldn't overwrite any metadata.
"""
-class DocumentTests(unittest.TestCase):
-
- def setUp( self ):
- get_transaction().begin()
+class DocumentTests(RequestTest):
- def tearDown( self ):
- get_transaction().abort()
+ def setUp(self):
+ RequestTest.setUp(self)
+ self.d = Document('foo')
def test_Empty(self):
d = Document('foo', text_format='structured-text')
@@ -136,13 +139,12 @@
self.assertEqual( d._stx_level, 1 )
def test_BasicHtmlPUT(self):
- REQUEST = fakeRequest()
- REQUEST['BODY'] = BASIC_HTML
- d = Document('foo')
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ self.REQUEST['BODY'] = BASIC_HTML
+ d = self.d
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.Format(), 'text/html' )
self.assertEqual( d.title, 'Title in tag' )
- self.assertEqual( string.find(d.text, '</body>'), -1 )
+ 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)' )
@@ -162,86 +164,79 @@
] )
def test_UpperedHtml(self):
- REQUEST=fakeRequest()
- REQUEST['BODY'] = string.upper(BASIC_HTML)
- d = Document('foo')
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ self.REQUEST['BODY'] = BASIC_HTML.upper()
+ d = self.d
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.Format(), 'text/html' )
self.assertEqual( d.title, 'TITLE IN TAG' )
- self.assertEqual( string.find(d.text, '</BODY'), -1 )
+ self.assertEqual( d.text.find('</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())
+ self.REQUEST['BODY'] = ENTITY_IN_TITLE
+ d = self.d
+ d.PUT(self.REQUEST, self.RESPONSE)
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())
+ d = self.d
+ self.REQUEST['BODY'] = '%s\n%s' % (DOCTYPE, BASIC_HTML)
+ d.PUT(self.REQUEST, self.RESPONSE)
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())
+ d = self.d
+ self.REQUEST['BODY'] = ''.join((BASIC_HTML.split('\n')))
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.Format(), 'text/html' )
self.assertEqual( d.Description(), 'Describe me' )
def test_BigHtml(self):
- REQUEST = fakeRequest()
- d = Document('foo')
+ d = self.d
s = []
looper = '<li> number %s</li>'
for i in range(12000): s.append(looper % i)
- body = '<ul>\n%s\n</ul>' % string.join(s, '\n')
- REQUEST['BODY'] = HTML_TEMPLATE % {'title': 'big document',
+ body = '<ul>\n%s\n</ul>' % '\n'.join(s)
+ self.REQUEST['BODY'] = HTML_TEMPLATE % {'title': 'big document',
'body': body}
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.CookedBody(), body )
def test_BigHtml_via_upload(self):
- d = Document('foo')
+ d = self.d
s = []
looper = '<li> number %s</li>'
for i in range(12000): s.append(looper % i)
- body = '<ul>\n%s\n</ul>' % string.join(s, '\n')
+ body = '<ul>\n%s\n</ul>' % '\n'.join(s)
html = HTML_TEMPLATE % {'title': 'big document',
'body': body}
- from StringIO import StringIO
file = StringIO( html )
d.edit(text_format='html', text='', file=file)
self.assertEqual( d.CookedBody(), body )
def test_EditStructuredTextWithHTML(self):
- d = Document('foo')
+ d = self.d
d.edit(text_format='structured-text', text=STX_WITH_HTML)
self.assertEqual( d.Format(), 'text/plain' )
def test_StructuredText(self):
- REQUEST=fakeRequest()
- REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
- d = Document('foo')
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
+ d = self.d
+ d.PUT(self.REQUEST, self.RESPONSE)
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 )
+ self.failUnless( d.cooked_text.find('<p>') >= 0 )
+ self.failUnless( d.CookedBody().find('<h1') >= 0 )
# Make sure extra HTML is NOT found
- self.failUnless( string.find(d.cooked_text, '<title>') < 0 )
- self.failUnless( string.find(d.cooked_text, '<body>') < 0 )
+ self.failUnless( d.cooked_text.find('<title>') < 0 )
+ self.failUnless( d.cooked_text.find('<body>') < 0 )
# test subject/keyword headers
subj = list(d.Subject())
@@ -254,43 +249,42 @@
] )
def test_STX_Levels(self):
- d = Document('foo')
+ d = self.d
d.edit(text_format='structured-text', text=BASIC_STRUCTUREDTEXT)
self.assertEqual( d._stx_level, 1 )
ct = d.CookedBody()
- self.failUnless( string.find(d.CookedBody(), '<h1') >= 0 )
+ self.failUnless( d.CookedBody().find('<h1') >= 0 )
self.assertEqual( d._stx_level, 1 )
ct = d.CookedBody(stx_level=2)
- self.failIf( (string.find(ct, '<h1') >= 0) )
- self.failUnless( string.find(ct, '<h2') >= 0 )
+ self.failIf( ct.find('<h1') >= 0 )
+ self.failUnless( ct.find('<h2') >= 0 )
self.assertEqual( d._stx_level, 1 )
ct = d.CookedBody(stx_level=2, setlevel=1)
- self.failIf( (string.find(ct, '<h1') >= 0) )
- self.failUnless( string.find(ct, '<h2') >= 0 )
+ self.failIf( ct.find('<h1') >= 0 )
+ self.failUnless( ct.find('<h2') >= 0 )
self.assertEqual( d._stx_level, 2 )
ct = d.CookedBody()
self.assertEqual( d._stx_level, 2 )
- self.failIf( (string.find(d.CookedBody(), '<h1') >= 0) )
- self.failUnless( string.find(d.CookedBody(), '<h2') >= 0 )
+ self.failIf( d.CookedBody().find('<h1') >= 0 )
+ self.failUnless( d.CookedBody().find('<h2') >= 0 )
def test_Init(self):
- REQUEST=fakeRequest()
- REQUEST['BODY']=BASIC_STRUCTUREDTEXT
- d = Document('foo')
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ self.REQUEST['BODY']=BASIC_STRUCTUREDTEXT
+ d = self.d
+ d.PUT(self.REQUEST, self.RESPONSE)
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( d.cooked_text.find('<p>') >= 0 )
d = Document('foo', text='')
- REQUEST['BODY']=BASIC_HTML
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ self.REQUEST['BODY']=BASIC_HTML
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.Format(), 'text/html' )
self.assertEqual( d.Title(), 'Title in tag' )
self.assertEqual( len(d.Contributors()), 3 )
@@ -308,9 +302,8 @@
self.assertEqual( d.Format(), 'text/plain' )
def test_STX_NoHeaders( self ):
- REQUEST=fakeRequest()
- REQUEST['BODY']=STX_NO_HEADERS
- d = Document('foo')
+ self.REQUEST['BODY']=STX_NO_HEADERS
+ d = self.d
d.editMetadata( title="Plain STX"
, description="Look, Ma, no headers!"
, subject=( "plain", "STX" )
@@ -322,7 +315,7 @@
self.failUnless( 'plain' in d.Subject() )
self.failUnless( 'STX' in d.Subject() )
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ d.PUT(self.REQUEST, self.RESPONSE)
self.assertEqual( d.Format(), 'text/plain' )
self.assertEqual( d.Title(), 'Plain STX' )
@@ -332,7 +325,7 @@
self.failUnless( 'STX' in d.Subject() )
def test_STX_NoHeaders_but_colon( self ):
- d = Document('foo')
+ d = self.d
d.editMetadata( title="Plain STX"
, description="Look, Ma, no headers!"
, subject=( "plain", "STX" )
@@ -342,7 +335,7 @@
self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )
def test_ZMI_edit( self ):
- d = Document('foo')
+ d = self.d
d.editMetadata( title="Plain STX"
, description="Look, Ma, no headers!"
, subject=( "plain", "STX" )
@@ -353,26 +346,25 @@
self.assertEqual( d.EditableBody(), STX_NO_HEADERS_BUT_COLON )
-class TestFTPGet( unittest.TestCase ):
+class TestFTPGet( RequestTest ):
def testHTML( self ):
- REQUEST=fakeRequest()
- REQUEST['BODY']=SIMPLE_HTML
+ self.REQUEST['BODY']=SIMPLE_HTML
d = Document( 'foo' )
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ d.PUT(self.REQUEST, self.RESPONSE)
- rnlinesplit = re.compile( r'\r?\n?' )
+ rnlinesplit = 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]*)" '
+ meta_pattern = compile( r'meta name="([a-z]*)" '
+ r'content="([a-z]*)"'
)
- title_pattern = re.compile( r'<title>(.*)</title>' )
+ title_pattern = compile( r'<title>(.*)</title>' )
simple_headers = []
while simple_lines and simple_lines[0] != '<BODY>':
- header = string.lower( string.strip( simple_lines[0] ) )
+ header = simple_lines[0].strip().lower()
match = meta_pattern.search( header )
if match:
simple_headers.append( match.groups() )
@@ -384,7 +376,7 @@
get_headers = []
while get_lines and get_lines[0] != '<BODY>':
- header = string.lower( string.strip( get_lines[0] ) )
+ header = get_lines[0].strip().lower()
match = meta_pattern.search( header )
if match:
get_headers.append( match.groups() )
@@ -404,12 +396,11 @@
self.failUnless( header in get_headers )
def testSTX( self ):
- REQUEST=fakeRequest()
- REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
+ self.REQUEST['BODY']=SIMPLE_STRUCTUREDTEXT
d = Document( 'foo' )
- d.PUT(REQUEST, RESPONSE=fakeResponse())
+ d.PUT(self.REQUEST, self.RESPONSE)
- rnlinesplit = re.compile( r'\r?\n?' )
+ rnlinesplit = compile( r'\r?\n?' )
get_text = d.manage_FTPget()
simple_lines = rnlinesplit.split( SIMPLE_STRUCTUREDTEXT )
@@ -431,68 +422,54 @@
for header in simple_headers:
self.failUnless( header in get_headers )
-class TestDocumentPUT(unittest.TestCase):
+class TestDocumentPUT(RequestTest):
+
def setUp(self):
- class Request:
- body = ''
- def get_header(self, h, d=''): return d
- def get(self, *args): return self.body
- class Response:
- status = 0
- def setHeader(self, *args): pass
- def setStatus(self, status): self.status = status
- self._request, self._response = Request(), Response()
-
- def tearDown(self):
- del self._response
- del self._request
+ RequestTest.setUp(self)
+ self.d = Document('foo')
def test_PutStructuredTextWithHTML(self):
- d = Document('foo')
- self._request.body = STX_WITH_HTML
+ self.REQUEST['BODY'] = STX_WITH_HTML
- r = d.PUT(self._request, self._response)
- self.assertEqual( d.Format(), 'text/plain' )
+ r = self.d.PUT(self.REQUEST, self.RESPONSE)
+ self.assertEqual( self.d.Format(), 'text/plain' )
self.assertEqual( r.status, 204 )
def test_PutStructuredText(self):
- d = Document('foo')
- self._request.body = BASIC_STRUCTUREDTEXT
+ self.REQUEST['BODY'] = BASIC_STRUCTUREDTEXT
- r = d.PUT(self._request, self._response)
- self.assertEqual( d.Format(), 'text/plain' )
+ r = self.d.PUT(self.REQUEST, self.RESPONSE)
+ self.assertEqual( self.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)
- self.assertEqual( d.Format(), 'text/html' )
- self.assertEqual( d.Description(), 'Describe me' )
+ 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):
- d = Document('foo')
- self._request.body = BASIC_HTML
- r = d.PUT(self._request, self._response)
- self.assertEqual( d.Format(), 'text/html' )
- self.assertEqual( d.Description(), 'Describe me' )
+
+ 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' )
self.assertEqual( r.status, 204 )
def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(DocumentTests))
- suite.addTest(unittest.makeSuite(TestFTPGet))
- suite.addTest(unittest.makeSuite(TestDocumentPUT))
- return suite
-
-def run():
- unittest.TextTestRunner().run(test_suite())
+ return TestSuite((
+ makeSuite(DocumentTests),
+ makeSuite(TestFTPGet),
+ makeSuite(TestDocumentPUT),
+ ))
if __name__ == '__main__':
- run()
+ main(defaultTest='test_suite')
=== Removed File CMF/CMFDefault/tests/utils.py ===