Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
GenericSetup.tests.test_context.TarballImportContextTests Class Reference
Inheritance diagram for GenericSetup.tests.test_context.TarballImportContextTests:
Inheritance graph
[legend]
Collaboration diagram for GenericSetup.tests.test_context.TarballImportContextTests:
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

Detailed Description

Definition at line 428 of file test_context.py.


Member Function Documentation

Definition at line 430 of file test_context.py.

00430 
00431     def _getTargetClass( self ):
00432 
00433         from Products.GenericSetup.context import TarballImportContext
00434         return TarballImportContext

def GenericSetup.tests.test_context.TarballImportContextTests._makeOne (   self,
  file_dict = {},
  mod_time = None,
  args,
  kw 
) [private]

Definition at line 435 of file test_context.py.

00435 
00436     def _makeOne( self, file_dict={}, mod_time=None, *args, **kw ):
00437 
00438         archive_stream = StringIO()
00439         archive = TarFile.open('test.tar.gz', 'w:gz', archive_stream)
00440 
00441         def _addOneMember(path, data, modtime):
00442             stream = StringIO(v)
00443             info = TarInfo(k)
00444             info.size = len(v)
00445             info.mtime = mod_time
00446             archive.addfile(info, stream)
00447 
00448         def _addMember(path, data, modtime):
00449             from tarfile import DIRTYPE
00450             elements = path.split('/')
00451             parents = filter(None, [elements[x] for x in range(len(elements))])
00452             for parent in parents:
00453                 info = TarInfo()
00454                 info.name = parent
00455                 info.size = 0
00456                 info.mtime = mod_time
00457                 info.type = DIRTYPE
00458                 archive.addfile(info, StringIO())
00459             _addOneMember(path, data, modtime)
00460 
00461         file_items = file_dict.items() or [('dummy', '')] # empty archive barfs
00462 
00463         if mod_time is None:
00464             mod_time = time.time()
00465 
00466         for k, v in file_items:
00467             _addMember(k, v, mod_time)
00468 
00469         archive.close()
00470         bits = archive_stream.getvalue()
00471 
00472         site = DummySite('site').__of__(self.app)
00473         site._setObject( 'setup_tool', Folder( 'setup_tool' ) )
00474         tool = site._getOb( 'setup_tool' )
00475 
00476         ctx = self._getTargetClass()( tool, bits, *args, **kw )
00477 
00478         return site, tool, ctx.__of__( tool )

Definition at line 496 of file test_context.py.

00496 
00497     def test_ctorparms( self ):
00498 
00499         ENCODING = 'latin-1'
00500         site, tool, ctx = self._makeOne( encoding=ENCODING
00501                                        , should_purge=True
00502                                        )
00503 
00504         self.assertEqual( ctx.getEncoding(), ENCODING )
00505         self.assertEqual( ctx.shouldPurge(), True )

Definition at line 506 of file test_context.py.

00506 
00507     def test_empty( self ):
00508 
00509         site, tool, ctx = self._makeOne()
00510 
00511         self.assertEqual( ctx.getSite(), site )
00512         self.assertEqual( ctx.getEncoding(), None )
00513         self.assertEqual( ctx.shouldPurge(), False )
00514 
00515         # These methods are all specified to return 'None' for non-existing
00516         # paths / entities
00517         self.assertEqual( ctx.isDirectory( 'nonesuch/path' ), None )
00518         self.assertEqual( ctx.listDirectory( 'nonesuch/path' ), None )

Definition at line 584 of file test_context.py.

00584 
00585     def test_getLastModified_directory( self ):
00586 
00587         from string import printable
00588 
00589         FILENAME = 'subdir.txt'
00590         SUBDIR = 'subdir'
00591         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00592         WHEN = DateTime( '2004-01-01T00:00:00Z' )
00593 
00594         site, tool, ctx = self._makeOne( { PATH: printable }
00595                                        , mod_time=WHEN
00596                                        )
00597 
00598         self.assertEqual( ctx.getLastModified( SUBDIR ), WHEN )

Definition at line 550 of file test_context.py.

00550 
00551     def test_getLastModified_nonesuch( self ):
00552 
00553         FILENAME = 'nonesuch.txt'
00554 
00555         site, tool, ctx = self._makeOne()
00556 
00557         self.assertEqual( ctx.getLastModified( FILENAME ), None )

Definition at line 558 of file test_context.py.

00558 
00559     def test_getLastModified_simple( self ):
00560 
00561         from string import printable
00562 
00563         FILENAME = 'simple.txt'
00564         WHEN = DateTime( '2004-01-01T00:00:00Z' )
00565 
00566         site, tool, ctx = self._makeOne( { FILENAME : printable }
00567                                        , mod_time=WHEN )
00568 
00569         self.assertEqual( ctx.getLastModified( FILENAME ), WHEN )

Definition at line 570 of file test_context.py.

00570 
00571     def test_getLastModified_subdir( self ):
00572 
00573         from string import printable
00574 
00575         FILENAME = 'subdir.txt'
00576         SUBDIR = 'subdir'
00577         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00578         WHEN = DateTime( '2004-01-01T00:00:00Z' )
00579 
00580         site, tool, ctx = self._makeOne( { PATH: printable }
00581                                        , mod_time=WHEN )
00582 
00583         self.assertEqual( ctx.getLastModified( PATH ), WHEN )

Definition at line 479 of file test_context.py.

00479 
00480     def test_getLogger( self ):
00481 
00482         site, tool, ctx = self._makeOne()
00483         self.assertEqual( len( ctx.listNotes() ), 0 )
00484 
00485         logger = ctx.getLogger('foo')
00486         logger.info('bar')
00487 
00488         self.assertEqual( len( ctx.listNotes() ), 1 )
00489         level, component, message = ctx.listNotes()[0]
00490         self.assertEqual( level, logging.INFO )
00491         self.assertEqual( component, 'foo' )
00492         self.assertEqual( message, 'bar' )
00493 
00494         ctx.clearNotes()
00495         self.assertEqual( len( ctx.listNotes() ), 0 )

Definition at line 617 of file test_context.py.

00617 
00618     def test_isDirectory_nested( self ):
00619 
00620         from string import printable
00621 
00622         SUBDIR = 'subdir'
00623         FILENAME = 'nested.txt'
00624         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00625 
00626         site, tool, ctx = self._makeOne( { PATH: printable } )
00627 
00628         self.assertEqual( ctx.isDirectory( PATH ), False )

Definition at line 599 of file test_context.py.

00599 
00600     def test_isDirectory_nonesuch( self ):
00601 
00602         FILENAME = 'nonesuch.txt'
00603 
00604         site, tool, ctx = self._makeOne()
00605 
00606         self.assertEqual( ctx.isDirectory( FILENAME ), None )

Definition at line 607 of file test_context.py.

00607 
00608     def test_isDirectory_simple( self ):
00609 
00610         from string import printable
00611 
00612         FILENAME = 'simple.txt'
00613 
00614         site, tool, ctx = self._makeOne( { FILENAME: printable } )
00615 
00616         self.assertEqual( ctx.isDirectory( FILENAME ), False )

Definition at line 629 of file test_context.py.

00629 
00630     def test_isDirectory_subdir( self ):
00631 
00632         from string import printable
00633 
00634         SUBDIR = 'subdir'
00635         FILENAME = 'nested.txt'
00636         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00637 
00638         site, tool, ctx = self._makeOne( { PATH: printable } )
00639 
00640         self.assertEqual( ctx.isDirectory( SUBDIR ), True )

Definition at line 696 of file test_context.py.

00696 
00697     def test_listDirectory_multiple( self ):
00698 
00699         from string import printable, uppercase
00700 
00701         SUBDIR = 'subdir'
00702         FILENAME1 = 'nested.txt'
00703         PATH1 = '%s/%s' % ( SUBDIR, FILENAME1 )
00704         FILENAME2 = 'another.txt'
00705         PATH2 = '%s/%s' % ( SUBDIR, FILENAME2 )
00706 
00707         site, tool, ctx = self._makeOne( { PATH1: printable
00708                                          , PATH2: uppercase
00709                                          } )
00710                                              
00711         names = ctx.listDirectory( SUBDIR )
00712         self.assertEqual( len( names ), 2 )
00713         self.failUnless( FILENAME1 in names )
00714         self.failUnless( FILENAME2 in names )

Definition at line 670 of file test_context.py.

00670 
00671     def test_listDirectory_nested( self ):
00672 
00673         from string import printable
00674 
00675         SUBDIR = 'subdir'
00676         FILENAME = 'nested.txt'
00677         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00678 
00679         site, tool, ctx = self._makeOne( { PATH: printable } )
00680 
00681         self.assertEqual( ctx.listDirectory( PATH ), None )

Definition at line 641 of file test_context.py.

00641 
00642     def test_listDirectory_nonesuch( self ):
00643 
00644         SUBDIR = 'nonesuch/path'
00645 
00646         site, tool, ctx = self._makeOne()
00647 
00648         self.assertEqual( ctx.listDirectory( SUBDIR ), None )

Definition at line 649 of file test_context.py.

00649 
00650     def test_listDirectory_root( self ):
00651 
00652         from string import printable
00653 
00654         FILENAME = 'simple.txt'
00655 
00656         site, tool, ctx = self._makeOne( { FILENAME: printable } )
00657 
00658         self.assertEqual( len( ctx.listDirectory( None ) ), 1 )
00659         self.failUnless( FILENAME in ctx.listDirectory( None ) )

Definition at line 660 of file test_context.py.

00660 
00661     def test_listDirectory_simple( self ):
00662 
00663         from string import printable
00664 
00665         FILENAME = 'simple.txt'
00666 
00667         site, tool, ctx = self._makeOne( { FILENAME: printable } )
00668 
00669         self.assertEqual( ctx.listDirectory( FILENAME ), None )

Definition at line 682 of file test_context.py.

00682 
00683     def test_listDirectory_single( self ):
00684 
00685         from string import printable
00686 
00687         SUBDIR = 'subdir'
00688         FILENAME = 'nested.txt'
00689         PATH = '%s/%s' % ( SUBDIR, FILENAME )
00690 
00691         site, tool, ctx = self._makeOne( { PATH: printable } )
00692 
00693         names = ctx.listDirectory( SUBDIR )
00694         self.assertEqual( len( names ), 1 )
00695         self.failUnless( FILENAME in names )

Definition at line 715 of file test_context.py.

00715 
00716     def test_listDirectory_skip( self ):
00717 
00718         from string import printable, uppercase
00719 
00720         SUBDIR = 'subdir'
00721         FILENAME1 = 'nested.txt'
00722         PATH1 = '%s/%s' % ( SUBDIR, FILENAME1 )
00723         FILENAME2 = 'another.txt'
00724         PATH2 = '%s/%s' % ( SUBDIR, FILENAME2 )
00725         FILENAME3 = 'another.bak'
00726         PATH3 = '%s/%s' % ( SUBDIR, FILENAME3 )
00727 
00728         site, tool, ctx = self._makeOne( { PATH1: printable
00729                                          , PATH2: uppercase
00730                                          , PATH3: 'xyz'
00731                                          } )
00732 
00733         names = ctx.listDirectory(SUBDIR, skip=(FILENAME1,),
00734                                   skip_suffixes=('.bak',))
00735         self.assertEqual( len( names ), 1 )
00736         self.failIf( FILENAME1 in names )
00737         self.failUnless( FILENAME2 in names )
00738         self.failIf( FILENAME3 in names )
00739 

Definition at line 519 of file test_context.py.

00519 
00520     def test_readDataFile_nonesuch( self ):
00521 
00522         FILENAME = 'nonesuch.txt'
00523 
00524         site, tool, ctx = self._makeOne()
00525 
00526         self.assertEqual( ctx.readDataFile( FILENAME ), None )
00527         self.assertEqual( ctx.readDataFile( FILENAME, 'subdir' ), None )

Definition at line 528 of file test_context.py.

00528 
00529     def test_readDataFile_simple( self ):
00530 
00531         from string import printable
00532 
00533         FILENAME = 'simple.txt'
00534 
00535         site, tool, ctx = self._makeOne( { FILENAME: printable } )
00536 
00537         self.assertEqual( ctx.readDataFile( FILENAME ), printable )

Definition at line 538 of file test_context.py.

00538 
00539     def test_readDataFile_subdir( self ):
00540 
00541         from string import printable
00542 
00543         FILENAME = 'subdir.txt'
00544         SUBDIR = 'subdir'
00545 
00546         site, tool, ctx = self._makeOne( { '%s/%s' % (SUBDIR, FILENAME):
00547                                             printable } )
00548 
00549         self.assertEqual( ctx.readDataFile( FILENAME, SUBDIR ), printable )


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