[Zope-CVS] CVS: Products/Zelenium/tests - test_zuite.py:1.2
Tres Seaver
tseaver at zope.com
Wed May 4 11:24:35 EDT 2005
Update of /cvs-repository/Products/Zelenium/tests
In directory cvs.zope.org:/tmp/cvs-serv25919/tests
Modified Files:
test_zuite.py
Log Message:
- Fix recursive ZIPfile generation, including synthesized URLs; add tests.
=== Products/Zelenium/tests/test_zuite.py 1.1 => 1.2 ===
--- Products/Zelenium/tests/test_zuite.py:1.1 Mon May 2 22:25:10 2005
+++ Products/Zelenium/tests/test_zuite.py Wed May 4 11:24:35 2005
@@ -124,6 +124,76 @@
self.failUnless( 'Page Template' in zuite.test_case_metatypes )
self.assertEqual( len( zuite.listTestCases() ), 0 )
+ def test_listTestCases_simple( self ):
+
+ _TEST_IDS = ( 'test_one'
+ , 'test_two'
+ , 'test_three'
+ )
+
+ zuite = self._makeOne()
+
+ for test_id in _TEST_IDS:
+ zuite._setObject( test_id, self._makeFile( test_id ) )
+
+ cases = zuite.listTestCases()
+ self.assertEqual( len( cases ), len( _TEST_IDS ) )
+ for case in cases:
+ self.failUnless( case[ 'id' ] in _TEST_IDS )
+
+ zuite.test_case_metatypes = ()
+ self.assertEqual( len( zuite.listTestCases() ), 0 )
+
+ zuite.test_case_metatypes = ( 'File', )
+ cases = zuite.listTestCases()
+ self.assertEqual( len( cases ), len( _TEST_IDS ) )
+ for case in cases:
+ self.failUnless( case[ 'id' ] in _TEST_IDS )
+
+ def test_listTestCases_recursive( self ):
+
+ _TEST_IDS = ( 'test_one'
+ , 'test_two'
+ , 'test_three'
+ )
+
+ _SUB_IDS = tuple( [ x + '_sub' for x in _TEST_IDS[:-1] ] )
+
+ # Create a zuite inside a zuite, each populated with testcases.
+ zuite = self._makeOne()
+
+ for test_id in _TEST_IDS:
+ zuite._setObject( test_id, self._makeFile( test_id ) )
+
+ sub = self._makeOne()
+
+ for sub_id in _SUB_IDS:
+ sub._setObject( sub_id, self._makeFile( sub_id ) )
+
+ zuite._setObject( 'sub', sub )
+
+ # verify that the default settings pick up all tests.
+ cases = zuite.listTestCases()
+ expected = _TEST_IDS + _SUB_IDS
+ self.assertEqual( len( cases ), len( expected ) )
+ for case in cases:
+ self.failUnless( case[ 'id' ] in expected )
+
+ # verfiy that disabling the parent's metatypes leaves the child's OK.
+ zuite.test_case_metatypes = ()
+ cases = zuite.listTestCases()
+ self.assertEqual( len( cases ), len( _SUB_IDS ) )
+ for case in cases:
+ self.failUnless( case[ 'id' ] in _SUB_IDS )
+
+ # verfiy that disabling the child's metatypes leaves the parent's OK.
+ zuite.test_case_metatypes = ( 'File', )
+ sub.test_case_metatypes = ()
+ cases = zuite.listTestCases()
+ self.assertEqual( len( cases ), len( _TEST_IDS ) )
+ for case in cases:
+ self.failUnless( case[ 'id' ] in _TEST_IDS )
+
def test_getZipFileName( self ):
_ID = 'gzf'
@@ -136,17 +206,18 @@
def test_manage_getZipFile_empty( self ):
-
_ID = 'mgzf_empty'
- zuite = self._makeOne( _ID ).__of__( self.root )
+ _ARCHIVE_NAME = 'empty.zip'
+
response = DummyResponse()
+ zuite = self._makeOne( _ID ).__of__( self.root )
- zuite.manage_getZipFile( archive_name='empty.zip', RESPONSE=response )
+ zuite.manage_getZipFile( archive_name=_ARCHIVE_NAME, RESPONSE=response )
self.assertEqual( response._headers[ 'Content-type' ]
, 'application/zip' )
self.assertEqual( response._headers[ 'Content-disposition' ]
- , 'inline;filename=empty.zip' )
+ , 'inline;filename=%s' % _ARCHIVE_NAME )
self.assertEqual( response._headers[ 'Content-length' ]
, str( len( response._body ) ) )
@@ -160,9 +231,9 @@
self._OLD_NOW = self._setNow( _NOW )
+ response = DummyResponse()
zuite = self._makeOne( _ID ).__of__( self.root )
zuite._setObject( _FILENAME, self._makeFile( _FILENAME ) )
- response = DummyResponse()
zuite.manage_getZipFile( RESPONSE=response )
@@ -174,13 +245,129 @@
, str( len( response._body ) ) )
expected = self._listDefaultArchiveNames()
- expected.append( 'test_one.html' )
+ expected.append( '%s.html' % _FILENAME )
self._verifyArchive( response._body, expected )
-
-# TODO: def test_listTestCases_simple( self ):
-# TODO: def test_listTestCases_recursive( self ):
-# TODO: def test_manage_createSnapshot_empty( self ):
-# TODO: def test_manage_createSnapshot_default_name( self ):
+
+ def test_manage_getZipFile_recursive( self ):
+
+ _ID = 'mgzf_recursive'
+ _ARCHIVE_NAME = 'recursive.zip'
+
+ _TEST_IDS = ( 'test_one'
+ , 'test_two'
+ , 'test_three'
+ )
+
+ _SUB_IDS = tuple( [ x + '_sub' for x in _TEST_IDS[:-1] ] )
+
+ response = DummyResponse()
+ zuite = self._makeOne( _ID ).__of__( self.root )
+
+ for test_id in _TEST_IDS:
+ zuite._setObject( test_id, self._makeFile( test_id ) )
+
+ sub = self._makeOne()
+
+ for sub_id in _SUB_IDS:
+ sub._setObject( sub_id, self._makeFile( sub_id ) )
+
+ zuite._setObject( 'sub', sub )
+
+ zuite.manage_getZipFile( archive_name=_ARCHIVE_NAME, RESPONSE=response )
+
+ self.assertEqual( response._headers[ 'Content-type' ]
+ , 'application/zip' )
+ self.assertEqual( response._headers[ 'Content-disposition' ]
+ , 'inline;filename=%s' % _ARCHIVE_NAME )
+ self.assertEqual( response._headers[ 'Content-length' ]
+ , str( len( response._body ) ) )
+
+ expected = self._listDefaultArchiveNames()
+
+ for test_id in _TEST_IDS:
+ expected.append( '%s.html' % test_id )
+
+ for sub_id in _SUB_IDS:
+ expected.append( 'sub/%s.html' % sub_id )
+
+ self._verifyArchive( response._body, expected )
+
+ def test_manage_createSnapshot_empty( self ):
+
+ _ID = 'mcs_empty'
+ _ARCHIVE_NAME = 'empty.zip'
+ zuite = self._makeOne( _ID ).__of__( self.root )
+
+ zuite.manage_createSnapshot( archive_name=_ARCHIVE_NAME )
+ object_ids = zuite.objectIds()
+ self.assertEqual( len( object_ids ), 1 )
+ self.failUnless( _ARCHIVE_NAME in object_ids )
+
+ archive = zuite._getOb( _ARCHIVE_NAME )
+ self._verifyArchive( archive.data, self._listDefaultArchiveNames() )
+
+ def test_manage_createSnapshot_default_name( self ):
+
+ _ID = 'mcs'
+ _NOW = '2005-05-02'
+ _FILENAME = 'test_one'
+
+ self._OLD_NOW = self._setNow( _NOW )
+
+ zuite = self._makeOne( _ID ).__of__( self.root )
+ zuite._setObject( _FILENAME, self._makeFile( _FILENAME ) )
+
+ zuite.manage_createSnapshot()
+
+ object_ids = zuite.objectIds()
+ self.assertEqual( len( object_ids ), 2 )
+ expected_id = '%s-%s.zip' % ( zuite.getId(), _NOW )
+ self.failUnless( expected_id in object_ids )
+
+ expected = self._listDefaultArchiveNames()
+ expected.append( '%s.html' % _FILENAME )
+ archive = zuite._getOb( expected_id )
+ self._verifyArchive( archive.data, expected )
+
+ def test_manage_createSnapshot_recursive( self ):
+
+ _ID = 'mgzf_recursive'
+ _ARCHIVE_NAME = 'recursive.zip'
+
+ _TEST_IDS = ( 'test_one'
+ , 'test_two'
+ , 'test_three'
+ )
+
+ _SUB_IDS = tuple( [ x + '_sub' for x in _TEST_IDS[:-1] ] )
+
+ zuite = self._makeOne( _ID ).__of__( self.root )
+
+ for test_id in _TEST_IDS:
+ zuite._setObject( test_id, self._makeFile( test_id ) )
+
+ sub = self._makeOne()
+
+ for sub_id in _SUB_IDS:
+ sub._setObject( sub_id, self._makeFile( sub_id ) )
+
+ zuite._setObject( 'sub', sub )
+
+ zuite.manage_createSnapshot( archive_name=_ARCHIVE_NAME )
+ object_ids = zuite.objectIds()
+ self.assertEqual( len( object_ids ), len( _TEST_IDS ) + 2 )
+ self.failUnless( _ARCHIVE_NAME in object_ids )
+
+ archive = zuite._getOb( _ARCHIVE_NAME )
+ expected = self._listDefaultArchiveNames()
+
+ for test_id in _TEST_IDS:
+ expected.append( '%s.html' % test_id )
+
+ for sub_id in _SUB_IDS:
+ expected.append( 'sub/%s.html' % sub_id )
+
+ self._verifyArchive( archive.data, expected )
def test_suite():
return unittest.TestSuite((
More information about the Zope-CVS
mailing list