[CMF-checkins] CVS: CMF/CMFSetup/tests - test_context.py:1.8
Tres Seaver
tseaver at zope.com
Mon Jul 19 14:04:18 EDT 2004
Update of /cvs-repository/CMF/CMFSetup/tests
In directory cvs.zope.org:/tmp/cvs-serv9216/CMFSetup/tests
Modified Files:
test_context.py
Log Message:
- Add a new SnapshotImportContext, to allow importing from (and later,
comparing with) snapshots.
=== CMF/CMFSetup/tests/test_context.py 1.7 => 1.8 ===
--- CMF/CMFSetup/tests/test_context.py:1.7 Sun May 30 16:29:50 2004
+++ CMF/CMFSetup/tests/test_context.py Mon Jul 19 14:04:18 2004
@@ -8,7 +8,10 @@
import time
from StringIO import StringIO
+from Acquisition import aq_parent
+from DateTime.DateTime import DateTime
from OFS.Folder import Folder
+from OFS.Image import File
from Products.CMFCore.tests.base.testcase import SecurityRequestTest
@@ -42,185 +45,196 @@
def test_readDataFile_nonesuch( self ):
- _FILENAME = 'nonesuch.txt'
+ FILENAME = 'nonesuch.txt'
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.readDataFile( _FILENAME ), None )
+ self.assertEqual( ctx.readDataFile( FILENAME ), None )
def test_readDataFile_simple( self ):
from string import printable
- _FILENAME = 'simple.txt'
- self._makeFile( _FILENAME, printable )
+
+ FILENAME = 'simple.txt'
+ self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.readDataFile( _FILENAME ), printable )
+ self.assertEqual( ctx.readDataFile( FILENAME ), printable )
def test_readDataFile_subdir( self ):
from string import printable
- _FILENAME = 'subdir/nested.txt'
- self._makeFile( _FILENAME, printable )
+
+ FILENAME = 'subdir/nested.txt'
+ self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.readDataFile( _FILENAME ), printable )
+ self.assertEqual( ctx.readDataFile( FILENAME ), printable )
def test_getLastModified_nonesuch( self ):
- _FILENAME = 'nonesuch.txt'
+ FILENAME = 'nonesuch.txt'
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.getLastModified( _FILENAME ), None )
+ self.assertEqual( ctx.getLastModified( FILENAME ), None )
def test_getLastModified_simple( self ):
from string import printable
- _FILENAME = 'simple.txt'
- fqpath = self._makeFile( _FILENAME, printable )
+
+ FILENAME = 'simple.txt'
+ fqpath = self._makeFile( FILENAME, printable )
timestamp = os.path.getmtime( fqpath )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.getLastModified( _FILENAME ), timestamp )
+ self.assertEqual( ctx.getLastModified( FILENAME ), timestamp )
- def test_getLastModified_nested( self ):
+ def test_getLastModified_subdir( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- fqpath = self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ fqpath = self._makeFile( FILENAME, printable )
timestamp = os.path.getmtime( fqpath )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.getLastModified( _FILENAME ), timestamp )
+ self.assertEqual( ctx.getLastModified( FILENAME ), timestamp )
def test_getLastModified_directory( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- fqpath = self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ fqpath = self._makeFile( FILENAME, printable )
path, file = os.path.split( fqpath )
timestamp = os.path.getmtime( path )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.getLastModified( _SUBDIR ), timestamp )
+ self.assertEqual( ctx.getLastModified( SUBDIR ), timestamp )
def test_isDirectory_nonesuch( self ):
- _FILENAME = 'nonesuch.txt'
+ FILENAME = 'nonesuch.txt'
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.isDirectory( _FILENAME ), None )
+ self.assertEqual( ctx.isDirectory( FILENAME ), None )
def test_isDirectory_simple( self ):
from string import printable
- _FILENAME = 'simple.txt'
- fqpath = self._makeFile( _FILENAME, printable )
+
+ FILENAME = 'simple.txt'
+ fqpath = self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.isDirectory( _FILENAME ), False )
+ self.assertEqual( ctx.isDirectory( FILENAME ), False )
def test_isDirectory_nested( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- fqpath = self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ fqpath = self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.isDirectory( _FILENAME ), False )
+ self.assertEqual( ctx.isDirectory( FILENAME ), False )
def test_isDirectory_directory( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- fqpath = self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ fqpath = self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.isDirectory( _SUBDIR ), True )
+ self.assertEqual( ctx.isDirectory( SUBDIR ), True )
def test_listDirectory_nonesuch( self ):
- _FILENAME = 'nonesuch.txt'
+ FILENAME = 'nonesuch.txt'
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.listDirectory( _FILENAME ), None )
+ self.assertEqual( ctx.listDirectory( FILENAME ), None )
def test_listDirectory_simple( self ):
from string import printable
- _FILENAME = 'simple.txt'
- self._makeFile( _FILENAME, printable )
+
+ FILENAME = 'simple.txt'
+ self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.listDirectory( _FILENAME ), None )
+ self.assertEqual( ctx.listDirectory( FILENAME ), None )
def test_listDirectory_nested( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- self.assertEqual( ctx.listDirectory( _FILENAME ), None )
+ self.assertEqual( ctx.listDirectory( FILENAME ), None )
def test_listDirectory_single( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- self._makeFile( _FILENAME, printable )
+
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- names = ctx.listDirectory( _SUBDIR )
+ names = ctx.listDirectory( SUBDIR )
self.assertEqual( len( names ), 1 )
self.failUnless( 'nested.txt' in names )
def test_listDirectory_multiple( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- self._makeFile( _FILENAME, printable )
- self._makeFile( os.path.join( _SUBDIR, 'another.txt' ), 'ABC' )
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ self._makeFile( FILENAME, printable )
+ self._makeFile( os.path.join( SUBDIR, 'another.txt' ), 'ABC' )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- names = ctx.listDirectory( _SUBDIR )
+ names = ctx.listDirectory( SUBDIR )
self.assertEqual( len( names ), 2 )
self.failUnless( 'nested.txt' in names )
self.failUnless( 'another.txt' in names )
@@ -228,16 +242,16 @@
def test_listDirectory_skip_implicit( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- self._makeFile( _FILENAME, printable )
- self._makeFile( os.path.join( _SUBDIR, 'another.txt' ), 'ABC' )
- self._makeFile( os.path.join( _SUBDIR, 'CVS/skip.txt' ), 'DEF' )
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ self._makeFile( FILENAME, printable )
+ self._makeFile( os.path.join( SUBDIR, 'another.txt' ), 'ABC' )
+ self._makeFile( os.path.join( SUBDIR, 'CVS/skip.txt' ), 'DEF' )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- names = ctx.listDirectory( _SUBDIR )
+ names = ctx.listDirectory( SUBDIR )
self.assertEqual( len( names ), 2 )
self.failUnless( 'nested.txt' in names )
self.failUnless( 'another.txt' in names )
@@ -246,16 +260,16 @@
def test_listDirectory_skip_explicit( self ):
from string import printable
- _SUBDIR = 'subdir'
- _FILENAME = os.path.join( _SUBDIR, 'nested.txt' )
- self._makeFile( _FILENAME, printable )
- self._makeFile( os.path.join( _SUBDIR, 'another.txt' ), 'ABC' )
- self._makeFile( os.path.join( _SUBDIR, 'CVS/skip.txt' ), 'DEF' )
+ SUBDIR = 'subdir'
+ FILENAME = os.path.join( SUBDIR, 'nested.txt' )
+ self._makeFile( FILENAME, printable )
+ self._makeFile( os.path.join( SUBDIR, 'another.txt' ), 'ABC' )
+ self._makeFile( os.path.join( SUBDIR, 'CVS/skip.txt' ), 'DEF' )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- names = ctx.listDirectory( _SUBDIR, ( 'nested.txt', ) )
+ names = ctx.listDirectory( SUBDIR, ( 'nested.txt', ) )
self.assertEqual( len( names ), 2 )
self.failIf( 'nested.txt' in names )
self.failUnless( 'another.txt' in names )
@@ -277,57 +291,57 @@
def test_writeDataFile_simple( self ):
from string import printable, digits
- _FILENAME = 'simple.txt'
- fqname = self._makeFile( _FILENAME, printable )
+ FILENAME = 'simple.txt'
+ fqname = self._makeFile( FILENAME, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- ctx.writeDataFile( _FILENAME, digits, 'text/plain' )
+ ctx.writeDataFile( FILENAME, digits, 'text/plain' )
self.assertEqual( open( fqname, 'rb' ).read(), digits )
def test_writeDataFile_new_subdir( self ):
from string import printable, digits
- _SUBDIR = 'subdir'
- _FILENAME = 'nested.txt'
- fqname = os.path.join( self._PROFILE_PATH, _SUBDIR, _FILENAME )
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ fqname = os.path.join( self._PROFILE_PATH, SUBDIR, FILENAME )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- ctx.writeDataFile( _FILENAME, digits, 'text/plain', _SUBDIR )
+ ctx.writeDataFile( FILENAME, digits, 'text/plain', SUBDIR )
self.assertEqual( open( fqname, 'rb' ).read(), digits )
def test_writeDataFile_overwrite( self ):
from string import printable, digits
- _SUBDIR = 'subdir'
- _FILENAME = 'nested.txt'
- fqname = self._makeFile( os.path.join( _SUBDIR, _FILENAME )
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ fqname = self._makeFile( os.path.join( SUBDIR, FILENAME )
, printable )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- ctx.writeDataFile( _FILENAME, digits, 'text/plain', _SUBDIR )
+ ctx.writeDataFile( FILENAME, digits, 'text/plain', SUBDIR )
self.assertEqual( open( fqname, 'rb' ).read(), digits )
def test_writeDataFile_existing_subdir( self ):
from string import printable, digits
- _SUBDIR = 'subdir'
- _FILENAME = 'nested.txt'
- self._makeFile( os.path.join( _SUBDIR, 'another.txt' ), printable )
- fqname = os.path.join( self._PROFILE_PATH, _SUBDIR, _FILENAME )
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ self._makeFile( os.path.join( SUBDIR, 'another.txt' ), printable )
+ fqname = os.path.join( self._PROFILE_PATH, SUBDIR, FILENAME )
site = DummySite( 'site' ).__of__( self.root )
ctx = self._makeOne( site, self._PROFILE_PATH )
- ctx.writeDataFile( _FILENAME, digits, 'text/plain', _SUBDIR )
+ ctx.writeDataFile( FILENAME, digits, 'text/plain', SUBDIR )
self.assertEqual( open( fqname, 'rb' ).read(), digits )
@@ -412,7 +426,7 @@
def test_writeDataFile_simple_image( self ):
from OFS.Image import Image
- _FILENAME = 'simple.txt'
+ FILENAME = 'simple.txt'
_CONTENT_TYPE = 'image/png'
png_filename = os.path.join( os.path.split( __file__ )[0]
, 'simple.png' )
@@ -425,16 +439,16 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, png_data, _CONTENT_TYPE )
+ ctx.writeDataFile( FILENAME, png_data, _CONTENT_TYPE )
snapshot = tool.snapshots._getOb( 'simple' )
self.assertEqual( len( snapshot.objectIds() ), 1 )
- self.failUnless( _FILENAME in snapshot.objectIds() )
+ self.failUnless( FILENAME in snapshot.objectIds() )
- fileobj = snapshot._getOb( _FILENAME )
+ fileobj = snapshot._getOb( FILENAME )
- self.assertEqual( fileobj.getId(), _FILENAME )
+ self.assertEqual( fileobj.getId(), FILENAME )
self.assertEqual( fileobj.meta_type, Image.meta_type )
self.assertEqual( fileobj.getContentType(), _CONTENT_TYPE )
self.assertEqual( fileobj.data, png_data )
@@ -443,7 +457,7 @@
from string import digits
from OFS.Image import File
- _FILENAME = 'simple.txt'
+ FILENAME = 'simple.txt'
_CONTENT_TYPE = 'text/plain'
site = DummySite( 'site' ).__of__( self.root )
@@ -451,16 +465,16 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, digits, _CONTENT_TYPE )
+ ctx.writeDataFile( FILENAME, digits, _CONTENT_TYPE )
snapshot = tool.snapshots._getOb( 'simple' )
self.assertEqual( len( snapshot.objectIds() ), 1 )
- self.failUnless( _FILENAME in snapshot.objectIds() )
+ self.failUnless( FILENAME in snapshot.objectIds() )
- fileobj = snapshot._getOb( _FILENAME )
+ fileobj = snapshot._getOb( FILENAME )
- self.assertEqual( fileobj.getId(), _FILENAME )
+ self.assertEqual( fileobj.getId(), FILENAME )
self.assertEqual( fileobj.meta_type, File.meta_type )
self.assertEqual( fileobj.getContentType(), _CONTENT_TYPE )
self.assertEqual( str( fileobj ), digits )
@@ -468,7 +482,7 @@
def test_writeDataFile_simple_xml( self ):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
- _FILENAME = 'simple.xml'
+ FILENAME = 'simple.xml'
_CONTENT_TYPE = 'text/xml'
_XML = """<?xml version="1.0"?><simple />"""
@@ -477,16 +491,16 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, _XML, _CONTENT_TYPE )
+ ctx.writeDataFile( FILENAME, _XML, _CONTENT_TYPE )
snapshot = tool.snapshots._getOb( 'simple' )
self.assertEqual( len( snapshot.objectIds() ), 1 )
- self.failUnless( _FILENAME in snapshot.objectIds() )
+ self.failUnless( FILENAME in snapshot.objectIds() )
- template = snapshot._getOb( _FILENAME )
+ template = snapshot._getOb( FILENAME )
- self.assertEqual( template.getId(), _FILENAME )
+ self.assertEqual( template.getId(), FILENAME )
self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
self.assertEqual( template.read(), _XML )
self.failIf( template.html() )
@@ -494,7 +508,7 @@
def test_writeDataFile_unicode_xml( self ):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
- _FILENAME = 'simple.xml'
+ FILENAME = 'simple.xml'
_CONTENT_TYPE = 'text/xml'
_XML = u"""<?xml version="1.0"?><simple />"""
@@ -503,16 +517,16 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, _XML, _CONTENT_TYPE )
+ ctx.writeDataFile( FILENAME, _XML, _CONTENT_TYPE )
snapshot = tool.snapshots._getOb( 'simple' )
self.assertEqual( len( snapshot.objectIds() ), 1 )
- self.failUnless( _FILENAME in snapshot.objectIds() )
+ self.failUnless( FILENAME in snapshot.objectIds() )
- template = snapshot._getOb( _FILENAME )
+ template = snapshot._getOb( FILENAME )
- self.assertEqual( template.getId(), _FILENAME )
+ self.assertEqual( template.getId(), FILENAME )
self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
self.assertEqual( template.read(), _XML )
self.failIf( template.html() )
@@ -520,7 +534,7 @@
def test_writeDataFile_subdir_dtml( self ):
from OFS.DTMLDocument import DTMLDocument
- _FILENAME = 'simple.dtml'
+ FILENAME = 'simple.dtml'
_CONTENT_TYPE = 'text/html'
_HTML = """<html><body><h1>HTML</h1></body></html>"""
@@ -529,24 +543,24 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, _HTML, _CONTENT_TYPE, 'sub1' )
+ ctx.writeDataFile( FILENAME, _HTML, _CONTENT_TYPE, 'sub1' )
snapshot = tool.snapshots._getOb( 'simple' )
sub1 = snapshot._getOb( 'sub1' )
self.assertEqual( len( sub1.objectIds() ), 1 )
- self.failUnless( _FILENAME in sub1.objectIds() )
+ self.failUnless( FILENAME in sub1.objectIds() )
- template = sub1._getOb( _FILENAME )
+ template = sub1._getOb( FILENAME )
- self.assertEqual( template.getId(), _FILENAME )
+ self.assertEqual( template.getId(), FILENAME )
self.assertEqual( template.meta_type, DTMLDocument.meta_type )
self.assertEqual( template.read(), _HTML )
def test_writeDataFile_nested_subdirs_html( self ):
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
- _FILENAME = 'simple.html'
+ FILENAME = 'simple.html'
_CONTENT_TYPE = 'text/html'
_HTML = """<html><body><h1>HTML</h1></body></html>"""
@@ -555,18 +569,18 @@
tool = site.portal_setup
ctx = self._makeOne( tool, 'simple' )
- ctx.writeDataFile( _FILENAME, _HTML, _CONTENT_TYPE, 'sub1/sub2' )
+ ctx.writeDataFile( FILENAME, _HTML, _CONTENT_TYPE, 'sub1/sub2' )
snapshot = tool.snapshots._getOb( 'simple' )
sub1 = snapshot._getOb( 'sub1' )
sub2 = sub1._getOb( 'sub2' )
self.assertEqual( len( sub2.objectIds() ), 1 )
- self.failUnless( _FILENAME in sub2.objectIds() )
+ self.failUnless( FILENAME in sub2.objectIds() )
- template = sub2._getOb( _FILENAME )
+ template = sub2._getOb( FILENAME )
- self.assertEqual( template.getId(), _FILENAME )
+ self.assertEqual( template.getId(), FILENAME )
self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
self.assertEqual( template.read(), _HTML )
self.failUnless( template.html() )
@@ -591,12 +605,333 @@
for id in [ 'foo.txt', 'bar.txt' ]:
self.failUnless( id in snapshot.objectIds() )
+
+class SnapshotImportContextTests( SecurityRequestTest
+ , ConformsToISetupContext
+ , ConformsToIImportContext
+ ):
+
+ def _getTargetClass( self ):
+
+ from Products.CMFSetup.context import SnapshotImportContext
+ return SnapshotImportContext
+
+ def _makeOne( self, context_id, *args, **kw ):
+
+ site = DummySite( 'site' ).__of__( self.root )
+ site._setObject( 'portal_setup', Folder( 'portal_setup' ) )
+ tool = site._getOb( 'portal_setup' )
+
+ tool._setObject( 'snapshots', Folder( 'snapshots' ) )
+ tool.snapshots._setObject( context_id, Folder( context_id ) )
+
+ ctx = self._getTargetClass()( tool, context_id, *args, **kw )
+
+ return site, tool, ctx.__of__( tool )
+
+ def _makeFile( self
+ , tool
+ , snapshot_id
+ , filename
+ , contents
+ , content_type='text/plain'
+ , mod_time=None
+ , subdir=None
+ ):
+
+ snapshots = tool._getOb( 'snapshots' )
+ folder = snapshot = snapshots._getOb( snapshot_id )
+
+ if subdir is not None:
+
+ for element in subdir.split( '/' ):
+
+ try:
+ folder = folder._getOb( element )
+ except AttributeError:
+ folder._setObject( element, Folder( element ) )
+ folder = folder._getOb( element )
+
+ file = File( filename, '', contents, content_type )
+ folder._setObject( filename, file )
+
+ if mod_time is not None:
+
+ def __faux_mod_time():
+ return mod_time
+
+ folder.bobobase_modification_time = \
+ file.bobobase_modification_time = __faux_mod_time
+
+ return folder._getOb( filename )
+
+ def test_ctorparms( self ):
+
+ SNAPSHOT_ID = 'ctorparms'
+ ENCODING = 'latin-1'
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID
+ , encoding=ENCODING
+ , should_purge=True
+ )
+
+ self.assertEqual( ctx.getEncoding(), ENCODING )
+ self.assertEqual( ctx.shouldPurge(), True )
+
+ def test_empty( self ):
+
+ SNAPSHOT_ID = 'empty'
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+
+ self.assertEqual( ctx.getSite(), site )
+ self.assertEqual( ctx.getEncoding(), None )
+ self.assertEqual( ctx.shouldPurge(), False )
+
+ # These methods are all specified to return 'None' for non-existing
+ # paths / entities
+ self.assertEqual( ctx.isDirectory( 'nonesuch/path' ), None )
+ self.assertEqual( ctx.listDirectory( 'nonesuch/path' ), None )
+
+ def test_readDataFile_nonesuch( self ):
+
+ SNAPSHOT_ID = 'readDataFile_nonesuch'
+ FILENAME = 'nonesuch.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+
+ self.assertEqual( ctx.readDataFile( FILENAME ), None )
+ self.assertEqual( ctx.readDataFile( FILENAME, 'subdir' ), None )
+
+ def test_readDataFile_simple( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'readDataFile_simple'
+ FILENAME = 'simple.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
+
+ self.assertEqual( ctx.readDataFile( FILENAME ), printable )
+
+ def test_readDataFile_subdir( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'readDataFile_subdir'
+ FILENAME = 'subdir.txt'
+ SUBDIR = 'subdir'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , subdir=SUBDIR )
+
+ self.assertEqual( ctx.readDataFile( FILENAME, SUBDIR ), printable )
+
+ def test_getLastModified_nonesuch( self ):
+
+ SNAPSHOT_ID = 'getLastModified_nonesuch'
+ FILENAME = 'nonesuch.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+
+ self.assertEqual( ctx.getLastModified( FILENAME ), None )
+
+ def test_getLastModified_simple( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'getLastModified_simple'
+ FILENAME = 'simple.txt'
+ WHEN = DateTime( '2004-01-01T00:00:00Z' )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , mod_time=WHEN )
+
+ self.assertEqual( ctx.getLastModified( FILENAME ), WHEN )
+
+ def test_getLastModified_subdir( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'getLastModified_subdir'
+ FILENAME = 'subdir.txt'
+ SUBDIR = 'subdir'
+ PATH = '%s/%s' % ( SUBDIR, FILENAME )
+ WHEN = DateTime( '2004-01-01T00:00:00Z' )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , mod_time=WHEN, subdir=SUBDIR )
+
+ self.assertEqual( ctx.getLastModified( PATH ), WHEN )
+
+ def test_getLastModified_directory( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'readDataFile_subdir'
+ FILENAME = 'subdir.txt'
+ SUBDIR = 'subdir'
+ WHEN = DateTime( '2004-01-01T00:00:00Z' )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , mod_time=WHEN, subdir=SUBDIR )
+
+ self.assertEqual( ctx.getLastModified( SUBDIR ), WHEN )
+
+ def test_isDirectory_nonesuch( self ):
+
+ SNAPSHOT_ID = 'isDirectory_nonesuch'
+ FILENAME = 'nonesuch.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+
+ self.assertEqual( ctx.isDirectory( FILENAME ), None )
+
+ def test_isDirectory_simple( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'isDirectory_simple'
+ FILENAME = 'simple.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
+
+ self.assertEqual( ctx.isDirectory( FILENAME ), False )
+
+ def test_isDirectory_nested( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'isDirectory_nested'
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ PATH = '%s/%s' % ( SUBDIR, FILENAME )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , subdir=SUBDIR )
+
+ self.assertEqual( ctx.isDirectory( PATH ), False )
+
+ def test_isDirectory_subdir( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'isDirectory_subdir'
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ PATH = '%s/%s' % ( SUBDIR, FILENAME )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , subdir=SUBDIR )
+
+ self.assertEqual( ctx.isDirectory( SUBDIR ), True )
+
+ def test_listDirectory_nonesuch( self ):
+
+ SNAPSHOT_ID = 'listDirectory_nonesuch'
+ SUBDIR = 'nonesuch/path'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+
+ self.assertEqual( ctx.listDirectory( SUBDIR ), None )
+
+ def test_listDirectory_simple( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'listDirectory_simple'
+ FILENAME = 'simple.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
+
+ self.assertEqual( ctx.listDirectory( FILENAME ), None )
+
+ def test_listDirectory_nested( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'listDirectory_nested'
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+ PATH = '%s/%s' % ( SUBDIR, FILENAME )
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , subdir=SUBDIR )
+
+ self.assertEqual( ctx.listDirectory( PATH ), None )
+
+ def test_listDirectory_single( self ):
+
+ from string import printable
+
+ SNAPSHOT_ID = 'listDirectory_nested'
+ SUBDIR = 'subdir'
+ FILENAME = 'nested.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
+ , subdir=SUBDIR )
+
+ names = ctx.listDirectory( SUBDIR )
+ self.assertEqual( len( names ), 1 )
+ self.failUnless( FILENAME in names )
+
+ def test_listDirectory_multiple( self ):
+
+ from string import printable, uppercase
+
+ SNAPSHOT_ID = 'listDirectory_nested'
+ SUBDIR = 'subdir'
+ FILENAME1 = 'nested.txt'
+ FILENAME2 = 'another.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file1 = self._makeFile( tool, SNAPSHOT_ID, FILENAME1, printable
+ , subdir=SUBDIR )
+ file2 = self._makeFile( tool, SNAPSHOT_ID, FILENAME2, uppercase
+ , subdir=SUBDIR )
+
+ names = ctx.listDirectory( SUBDIR )
+ self.assertEqual( len( names ), 2 )
+ self.failUnless( FILENAME1 in names )
+ self.failUnless( FILENAME2 in names )
+
+ def test_listDirectory_skip( self ):
+
+ from string import printable, uppercase
+
+ SNAPSHOT_ID = 'listDirectory_nested'
+ SUBDIR = 'subdir'
+ FILENAME1 = 'nested.txt'
+ FILENAME2 = 'another.txt'
+
+ site, tool, ctx = self._makeOne( SNAPSHOT_ID )
+ file1 = self._makeFile( tool, SNAPSHOT_ID, FILENAME1, printable
+ , subdir=SUBDIR )
+ file2 = self._makeFile( tool, SNAPSHOT_ID, FILENAME2, uppercase
+ , subdir=SUBDIR )
+
+ names = ctx.listDirectory( SUBDIR, skip=( FILENAME1, ) )
+ self.assertEqual( len( names ), 1 )
+ self.failIf( FILENAME1 in names )
+ self.failUnless( FILENAME2 in names )
+
+
def test_suite():
return unittest.TestSuite((
unittest.makeSuite( ImportContextTests ),
unittest.makeSuite( ExportContextTests ),
unittest.makeSuite( TarballExportContextTests ),
unittest.makeSuite( SnapshotExportContextTests ),
+ unittest.makeSuite( SnapshotImportContextTests ),
))
if __name__ == '__main__':
More information about the CMF-checkins
mailing list