Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
GenericSetup.tests.test_context.SnapshotImportContextTests Class Reference
Inheritance diagram for GenericSetup.tests.test_context.SnapshotImportContextTests:
Inheritance graph
[legend]
Collaboration diagram for GenericSetup.tests.test_context.SnapshotImportContextTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_getLogger
def test_ctorparms
def test_empty
def test_readDataFile_nonesuch
def test_readDataFile_simple
def test_readDataFile_subdir
def test_getLastModified_nonesuch
def test_getLastModified_simple
def test_getLastModified_subdir
def test_getLastModified_directory
def test_isDirectory_nonesuch
def test_isDirectory_simple
def test_isDirectory_nested
def test_isDirectory_subdir
def test_listDirectory_nonesuch
def test_listDirectory_root
def test_listDirectory_simple
def test_listDirectory_nested
def test_listDirectory_single
def test_listDirectory_multiple
def test_listDirectory_skip

Private Member Functions

def _getTargetClass
def _makeOne
def _makeFile

Detailed Description

Definition at line 1065 of file test_context.py.


Member Function Documentation

Definition at line 1067 of file test_context.py.

01067 
01068     def _getTargetClass( self ):
01069 
01070         from Products.GenericSetup.context import SnapshotImportContext
01071         return SnapshotImportContext

def GenericSetup.tests.test_context.SnapshotImportContextTests._makeFile (   self,
  tool,
  snapshot_id,
  filename,
  contents,
  content_type = 'text/plain',
  mod_time = None,
  subdir = None 
) [private]

Definition at line 1093 of file test_context.py.

01093 
01094                  ):
01095 
01096         snapshots = tool._getOb( 'snapshots' )
01097         folder = snapshot = snapshots._getOb( snapshot_id )
01098 
01099         if subdir is not None:
01100 
01101             for element in subdir.split( '/' ):
01102 
01103                 try:
01104                     folder = folder._getOb( element )
01105                 except AttributeError:
01106                     folder._setObject( element, Folder( element ) )
01107                     folder = folder._getOb( element )
01108 
01109         file = File( filename, '', contents, content_type )
01110         folder._setObject( filename, file )
01111 
01112         if mod_time is not None:
01113 
01114             def __faux_mod_time():
01115                 return mod_time
01116 
01117             folder.bobobase_modification_time = \
01118             file.bobobase_modification_time = __faux_mod_time
01119 
01120         return folder._getOb( filename )

def GenericSetup.tests.test_context.SnapshotImportContextTests._makeOne (   self,
  context_id,
  args,
  kw 
) [private]

Definition at line 1072 of file test_context.py.

01072 
01073     def _makeOne( self, context_id, *args, **kw ):
01074 
01075         site = DummySite('site').__of__(self.app)
01076         site._setObject( 'setup_tool', Folder( 'setup_tool' ) )
01077         tool = site._getOb( 'setup_tool' )
01078 
01079         tool._setObject( 'snapshots', Folder( 'snapshots' ) )
01080         tool.snapshots._setObject( context_id, Folder( context_id ) )
01081 
01082         ctx = self._getTargetClass()( tool, context_id, *args, **kw )
01083 
01084         return site, tool, ctx.__of__( tool )

Definition at line 1140 of file test_context.py.

01140 
01141     def test_ctorparms( self ):
01142 
01143         SNAPSHOT_ID = 'ctorparms'
01144         ENCODING = 'latin-1'
01145         site, tool, ctx = self._makeOne( SNAPSHOT_ID
01146                                        , encoding=ENCODING
01147                                        , should_purge=True
01148                                        )
01149 
01150         self.assertEqual( ctx.getEncoding(), ENCODING )
01151         self.assertEqual( ctx.shouldPurge(), True )

Definition at line 1152 of file test_context.py.

01152 
01153     def test_empty( self ):
01154 
01155         SNAPSHOT_ID = 'empty'
01156         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01157 
01158         self.assertEqual( ctx.getSite(), site )
01159         self.assertEqual( ctx.getEncoding(), None )
01160         self.assertEqual( ctx.shouldPurge(), False )
01161 
01162         # These methods are all specified to return 'None' for non-existing
01163         # paths / entities
01164         self.assertEqual( ctx.isDirectory( 'nonesuch/path' ), None )
01165         self.assertEqual( ctx.listDirectory( 'nonesuch/path' ), None )

Definition at line 1243 of file test_context.py.

01243 
01244     def test_getLastModified_directory( self ):
01245 
01246         from string import printable
01247 
01248         SNAPSHOT_ID = 'readDataFile_subdir'
01249         FILENAME = 'subdir.txt'
01250         SUBDIR = 'subdir'
01251         WHEN = DateTime( '2004-01-01T00:00:00Z' )
01252 
01253         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01254         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01255                              , mod_time=WHEN, subdir=SUBDIR )
01256 
01257         self.assertEqual( ctx.getLastModified( SUBDIR ), WHEN )

Definition at line 1204 of file test_context.py.

01204 
01205     def test_getLastModified_nonesuch( self ):
01206 
01207         SNAPSHOT_ID = 'getLastModified_nonesuch'
01208         FILENAME = 'nonesuch.txt'
01209 
01210         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01211 
01212         self.assertEqual( ctx.getLastModified( FILENAME ), None )

Definition at line 1213 of file test_context.py.

01213 
01214     def test_getLastModified_simple( self ):
01215 
01216         from string import printable
01217 
01218         SNAPSHOT_ID = 'getLastModified_simple'
01219         FILENAME = 'simple.txt'
01220         WHEN = DateTime( '2004-01-01T00:00:00Z' )
01221 
01222         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01223         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01224                              , mod_time=WHEN )
01225 
01226         self.assertEqual( ctx.getLastModified( FILENAME ), WHEN )

Definition at line 1227 of file test_context.py.

01227 
01228     def test_getLastModified_subdir( self ):
01229 
01230         from string import printable
01231 
01232         SNAPSHOT_ID = 'getLastModified_subdir'
01233         FILENAME = 'subdir.txt'
01234         SUBDIR = 'subdir'
01235         PATH = '%s/%s' % ( SUBDIR, FILENAME )
01236         WHEN = DateTime( '2004-01-01T00:00:00Z' )
01237 
01238         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01239         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01240                              , mod_time=WHEN, subdir=SUBDIR )
01241 
01242         self.assertEqual( ctx.getLastModified( PATH ), WHEN )

Definition at line 1121 of file test_context.py.

01121 
01122     def test_getLogger( self ):
01123 
01124         SNAPSHOT_ID = 'note'
01125         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01126 
01127         self.assertEqual( len( ctx.listNotes() ), 0 )
01128 
01129         logger = ctx.getLogger('foo')
01130         logger.info('bar')
01131 
01132         self.assertEqual( len( ctx.listNotes() ), 1 )
01133         level, component, message = ctx.listNotes()[0]
01134         self.assertEqual( level, logging.INFO )
01135         self.assertEqual( component, 'foo' )
01136         self.assertEqual( message, 'bar' )
01137 
01138         ctx.clearNotes()
01139         self.assertEqual( len( ctx.listNotes() ), 0 )

Definition at line 1279 of file test_context.py.

01279 
01280     def test_isDirectory_nested( self ):
01281 
01282         from string import printable
01283 
01284         SNAPSHOT_ID = 'isDirectory_nested'
01285         SUBDIR = 'subdir'
01286         FILENAME = 'nested.txt'
01287         PATH = '%s/%s' % ( SUBDIR, FILENAME )
01288 
01289         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01290         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01291                              , subdir=SUBDIR )
01292 
01293         self.assertEqual( ctx.isDirectory( PATH ), False )

Definition at line 1258 of file test_context.py.

01258 
01259     def test_isDirectory_nonesuch( self ):
01260 
01261         SNAPSHOT_ID = 'isDirectory_nonesuch'
01262         FILENAME = 'nonesuch.txt'
01263 
01264         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01265 
01266         self.assertEqual( ctx.isDirectory( FILENAME ), None )

Definition at line 1267 of file test_context.py.

01267 
01268     def test_isDirectory_simple( self ):
01269 
01270         from string import printable
01271 
01272         SNAPSHOT_ID = 'isDirectory_simple'
01273         FILENAME = 'simple.txt'
01274 
01275         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01276         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
01277 
01278         self.assertEqual( ctx.isDirectory( FILENAME ), False )

Definition at line 1294 of file test_context.py.

01294 
01295     def test_isDirectory_subdir( self ):
01296 
01297         from string import printable
01298 
01299         SNAPSHOT_ID = 'isDirectory_subdir'
01300         SUBDIR = 'subdir'
01301         FILENAME = 'nested.txt'
01302         PATH = '%s/%s' % ( SUBDIR, FILENAME )
01303 
01304         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01305         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01306                              , subdir=SUBDIR )
01307 
01308         self.assertEqual( ctx.isDirectory( SUBDIR ), True )

Definition at line 1374 of file test_context.py.

01374 
01375     def test_listDirectory_multiple( self ):
01376 
01377         from string import printable, uppercase
01378 
01379         SNAPSHOT_ID = 'listDirectory_nested'
01380         SUBDIR = 'subdir'
01381         FILENAME1 = 'nested.txt'
01382         FILENAME2 = 'another.txt'
01383 
01384         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01385         file1 = self._makeFile( tool, SNAPSHOT_ID, FILENAME1, printable
01386                               , subdir=SUBDIR )
01387         file2 = self._makeFile( tool, SNAPSHOT_ID, FILENAME2, uppercase
01388                               , subdir=SUBDIR )
01389 
01390         names = ctx.listDirectory( SUBDIR )
01391         self.assertEqual( len( names ), 2 )
01392         self.failUnless( FILENAME1 in names )
01393         self.failUnless( FILENAME2 in names )

Definition at line 1343 of file test_context.py.

01343 
01344     def test_listDirectory_nested( self ):
01345 
01346         from string import printable
01347 
01348         SNAPSHOT_ID = 'listDirectory_nested'
01349         SUBDIR = 'subdir'
01350         FILENAME = 'nested.txt'
01351         PATH = '%s/%s' % ( SUBDIR, FILENAME )
01352 
01353         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01354         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01355                              , subdir=SUBDIR )
01356 
01357         self.assertEqual( ctx.listDirectory( PATH ), None )

Definition at line 1309 of file test_context.py.

01309 
01310     def test_listDirectory_nonesuch( self ):
01311 
01312         SNAPSHOT_ID = 'listDirectory_nonesuch'
01313         SUBDIR = 'nonesuch/path'
01314 
01315         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01316 
01317         self.assertEqual( ctx.listDirectory( SUBDIR ), None )

Definition at line 1318 of file test_context.py.

01318 
01319     def test_listDirectory_root( self ):
01320 
01321         from string import printable
01322 
01323         SNAPSHOT_ID = 'listDirectory_root'
01324         FILENAME = 'simple.txt'
01325 
01326         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01327         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
01328 
01329         self.assertEqual( len( ctx.listDirectory( None ) ), 1 )
01330         self.failUnless( FILENAME in ctx.listDirectory( None ) )

Definition at line 1331 of file test_context.py.

01331 
01332     def test_listDirectory_simple( self ):
01333 
01334         from string import printable
01335 
01336         SNAPSHOT_ID = 'listDirectory_simple'
01337         FILENAME = 'simple.txt'
01338 
01339         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01340         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
01341 
01342         self.assertEqual( ctx.listDirectory( FILENAME ), None )

Definition at line 1358 of file test_context.py.

01358 
01359     def test_listDirectory_single( self ):
01360 
01361         from string import printable
01362 
01363         SNAPSHOT_ID = 'listDirectory_nested'
01364         SUBDIR = 'subdir'
01365         FILENAME = 'nested.txt'
01366 
01367         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01368         file = self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01369                              , subdir=SUBDIR )
01370 
01371         names = ctx.listDirectory( SUBDIR )
01372         self.assertEqual( len( names ), 1 )
01373         self.failUnless( FILENAME in names )

Definition at line 1394 of file test_context.py.

01394 
01395     def test_listDirectory_skip( self ):
01396 
01397         from string import printable, uppercase
01398 
01399         SNAPSHOT_ID = 'listDirectory_nested'
01400         SUBDIR = 'subdir'
01401         FILENAME1 = 'nested.txt'
01402         FILENAME2 = 'another.txt'
01403         FILENAME3 = 'another.bak'
01404 
01405         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01406         file1 = self._makeFile( tool, SNAPSHOT_ID, FILENAME1, printable
01407                               , subdir=SUBDIR )
01408         file2 = self._makeFile( tool, SNAPSHOT_ID, FILENAME2, uppercase
01409                               , subdir=SUBDIR )
01410         file3 = self._makeFile( tool, SNAPSHOT_ID, FILENAME3, 'abc'
01411                               , subdir=SUBDIR )
01412 
01413         names = ctx.listDirectory(SUBDIR, skip=(FILENAME1,),
01414                                   skip_suffixes=('.bak',))
01415         self.assertEqual( len( names ), 1 )
01416         self.failIf( FILENAME1 in names )
01417         self.failUnless( FILENAME2 in names )
01418         self.failIf( FILENAME3 in names )
01419 

Definition at line 1166 of file test_context.py.

01166 
01167     def test_readDataFile_nonesuch( self ):
01168 
01169         SNAPSHOT_ID = 'readDataFile_nonesuch'
01170         FILENAME = 'nonesuch.txt'
01171 
01172         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01173 
01174         self.assertEqual( ctx.readDataFile( FILENAME ), None )
01175         self.assertEqual( ctx.readDataFile( FILENAME, 'subdir' ), None )

Definition at line 1176 of file test_context.py.

01176 
01177     def test_readDataFile_simple( self ):
01178 
01179         from string import printable
01180 
01181         SNAPSHOT_ID = 'readDataFile_simple'
01182         FILENAME = 'simple.txt'
01183 
01184         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01185         self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable )
01186 
01187         self.assertEqual( ctx.readDataFile( FILENAME ), printable )

Definition at line 1188 of file test_context.py.

01188 
01189     def test_readDataFile_subdir( self ):
01190 
01191         from string import printable
01192 
01193         SNAPSHOT_ID = 'readDataFile_subdir'
01194         FILENAME = 'subdir.txt'
01195         SUBDIR = 'subdir'
01196 
01197         site, tool, ctx = self._makeOne( SNAPSHOT_ID )
01198         self._makeFile( tool, SNAPSHOT_ID, FILENAME, printable
01199                       , subdir=SUBDIR )
01200 
01201         self.assertEqual( ctx.readDataFile( FILENAME, SUBDIR ), printable )
01202         self.assertEqual( ctx.readDataFile( '%s/%s' % (SUBDIR, FILENAME) ),
01203                                             printable )


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