Back to index

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

List of all members.

Public Member Functions

def test_getLogger
def test_writeDataFile_simple_image
def test_writeDataFile_simple_plain_text
def test_writeDataFile_simple_plain_text_unicode
def test_writeDataFile_simple_xml
def test_writeDataFile_unicode_xml
def test_writeDataFile_subdir_dtml
def test_writeDataFile_nested_subdirs_html
def test_writeDataFile_multiple

Private Member Functions

def _getTargetClass
def _makeOne

Detailed Description

Definition at line 818 of file test_context.py.


Member Function Documentation

Definition at line 820 of file test_context.py.

00820 
00821     def _getTargetClass( self ):
00822 
00823         from Products.GenericSetup.context import SnapshotExportContext
00824         return SnapshotExportContext

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

Definition at line 825 of file test_context.py.

00825 
00826     def _makeOne( self, *args, **kw ):
00827 
00828         return self._getTargetClass()( *args, **kw )

Definition at line 829 of file test_context.py.

00829 
00830     def test_getLogger( self ):
00831 
00832         site = DummySite('site').__of__(self.app)
00833         site.setup_tool = DummyTool( 'setup_tool' )
00834         tool = site.setup_tool
00835         ctx = self._makeOne( tool, 'simple' )
00836 
00837         self.assertEqual( len( ctx.listNotes() ), 0 )
00838 
00839         logger = ctx.getLogger('foo')
00840         logger.info('bar')
00841 
00842         self.assertEqual( len( ctx.listNotes() ), 1 )
00843         level, component, message = ctx.listNotes()[0]
00844         self.assertEqual( level, logging.INFO )
00845         self.assertEqual( component, 'foo' )
00846         self.assertEqual( message, 'bar' )
00847 
00848         ctx.clearNotes()
00849         self.assertEqual( len( ctx.listNotes() ), 0 )

Definition at line 1043 of file test_context.py.

01043 
01044     def test_writeDataFile_multiple( self ):
01045 
01046         from string import printable
01047         from string import digits
01048 
01049         site = DummySite('site').__of__(self.app)
01050         site.setup_tool = DummyTool( 'setup_tool' )
01051         tool = site.setup_tool
01052         ctx = self._makeOne( tool, 'multiple' )
01053 
01054         ctx.writeDataFile( 'foo.txt', printable, 'text/plain' )
01055         ctx.writeDataFile( 'bar.txt', digits, 'text/plain' )
01056 
01057         snapshot = tool.snapshots._getOb( 'multiple' )
01058 
01059         self.assertEqual( len( snapshot.objectIds() ), 2 )
01060 
01061         for id in [ 'foo.txt', 'bar.txt' ]:
01062             self.failUnless( id in snapshot.objectIds() )
01063 

Definition at line 1015 of file test_context.py.

01015 
01016     def test_writeDataFile_nested_subdirs_html( self ):
01017 
01018         from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
01019         FILENAME = 'simple.html'
01020         CONTENT_TYPE = 'text/html'
01021         _HTML = """<html><body><h1>HTML</h1></body></html>"""
01022 
01023         site = DummySite('site').__of__(self.app)
01024         site.setup_tool = DummyTool( 'setup_tool' )
01025         tool = site.setup_tool
01026         ctx = self._makeOne( tool, 'simple' )
01027 
01028         ctx.writeDataFile( FILENAME, _HTML, CONTENT_TYPE, 'sub1/sub2' )
01029 
01030         snapshot = tool.snapshots._getOb( 'simple' )
01031         sub1 = snapshot._getOb( 'sub1' )
01032         sub2 = sub1._getOb( 'sub2' )
01033 
01034         self.assertEqual( len( sub2.objectIds() ), 1 )
01035         self.failUnless( FILENAME in sub2.objectIds() )
01036 
01037         template = sub2._getOb( FILENAME )
01038 
01039         self.assertEqual( template.getId(), FILENAME )
01040         self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
01041         self.assertEqual( template.read(), _HTML )
01042         self.failUnless( template.html() )

Definition at line 850 of file test_context.py.

00850 
00851     def test_writeDataFile_simple_image( self ):
00852 
00853         from OFS.Image import Image
00854         FILENAME = 'simple.txt'
00855         CONTENT_TYPE = 'image/png'
00856         png_filename = os.path.join( os.path.split( __file__ )[0]
00857                                    , 'simple.png' )
00858         png_file = open( png_filename, 'rb' )
00859         png_data = png_file.read()
00860         png_file.close()
00861 
00862         site = DummySite('site').__of__(self.app)
00863         site.setup_tool = DummyTool( 'setup_tool' )
00864         tool = site.setup_tool
00865         ctx = self._makeOne( tool, 'simple' )
00866 
00867         ctx.writeDataFile( FILENAME, png_data, CONTENT_TYPE )
00868 
00869         snapshot = tool.snapshots._getOb( 'simple' )
00870 
00871         self.assertEqual( len( snapshot.objectIds() ), 1 )
00872         self.failUnless( FILENAME in snapshot.objectIds() )
00873 
00874         fileobj = snapshot._getOb( FILENAME )
00875 
00876         self.assertEqual( fileobj.getId(), FILENAME )
00877         self.assertEqual( fileobj.meta_type, Image.meta_type )
00878         self.assertEqual( fileobj.getContentType(), CONTENT_TYPE )
00879         self.assertEqual( fileobj.data, png_data )

Definition at line 880 of file test_context.py.

00880 
00881     def test_writeDataFile_simple_plain_text( self ):
00882 
00883         from string import digits
00884         from OFS.Image import File
00885         FILENAME = 'simple.txt'
00886         CONTENT_TYPE = 'text/plain'
00887 
00888         site = DummySite('site').__of__(self.app)
00889         site.setup_tool = DummyTool( 'setup_tool' )
00890         tool = site.setup_tool
00891         ctx = self._makeOne( tool, 'simple' )
00892 
00893         ctx.writeDataFile( FILENAME, digits, CONTENT_TYPE )
00894 
00895         snapshot = tool.snapshots._getOb( 'simple' )
00896 
00897         self.assertEqual( len( snapshot.objectIds() ), 1 )
00898         self.failUnless( FILENAME in snapshot.objectIds() )
00899 
00900         fileobj = snapshot._getOb( FILENAME )
00901 
00902         self.assertEqual( fileobj.getId(), FILENAME )
00903         self.assertEqual( fileobj.meta_type, File.meta_type )
00904         self.assertEqual( fileobj.getContentType(), CONTENT_TYPE )
00905         self.assertEqual( str( fileobj ), digits )

Definition at line 906 of file test_context.py.

00906 
00907     def test_writeDataFile_simple_plain_text_unicode( self ):
00908 
00909         from string import digits
00910         from OFS.Image import File
00911         FILENAME = 'simple.txt'
00912         CONTENT_TYPE = 'text/plain'
00913         CONTENT = u'Unicode, with non-ASCII: %s.' % unichr(150)
00914 
00915         site = DummySite('site').__of__(self.app)
00916         site.setup_tool = DummyTool( 'setup_tool' )
00917         tool = site.setup_tool
00918         ctx = self._makeOne( tool, 'simple', 'latin_1' )
00919 
00920         ctx.writeDataFile( FILENAME, CONTENT, CONTENT_TYPE )
00921 
00922         snapshot = tool.snapshots._getOb( 'simple' )
00923 
00924         self.assertEqual( len( snapshot.objectIds() ), 1 )
00925         self.failUnless( FILENAME in snapshot.objectIds() )
00926 
00927         fileobj = snapshot._getOb( FILENAME )
00928 
00929         self.assertEqual( fileobj.getId(), FILENAME )
00930         self.assertEqual( fileobj.meta_type, File.meta_type )
00931         self.assertEqual( fileobj.getContentType(), CONTENT_TYPE )
00932         saved = fileobj.manage_FTPget().decode('latin_1')
00933         self.assertEqual( saved, CONTENT )

Definition at line 934 of file test_context.py.

00934 
00935     def test_writeDataFile_simple_xml( self ):
00936 
00937         from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
00938         FILENAME = 'simple.xml'
00939         CONTENT_TYPE = 'text/xml'
00940         _XML = """<?xml version="1.0"?><simple />"""
00941 
00942         site = DummySite('site').__of__(self.app)
00943         site.setup_tool = DummyTool( 'setup_tool' )
00944         tool = site.setup_tool
00945         ctx = self._makeOne( tool, 'simple' )
00946 
00947         ctx.writeDataFile( FILENAME, _XML, CONTENT_TYPE )
00948 
00949         snapshot = tool.snapshots._getOb( 'simple' )
00950 
00951         self.assertEqual( len( snapshot.objectIds() ), 1 )
00952         self.failUnless( FILENAME in snapshot.objectIds() )
00953 
00954         template = snapshot._getOb( FILENAME )
00955 
00956         self.assertEqual( template.getId(), FILENAME )
00957         self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
00958         self.assertEqual( template.read(), _XML )
00959         self.failIf( template.html() )

Definition at line 986 of file test_context.py.

00986 
00987     def test_writeDataFile_subdir_dtml( self ):
00988 
00989         from OFS.DTMLDocument import DTMLDocument
00990         FILENAME = 'simple.dtml'
00991         CONTENT_TYPE = 'text/html'
00992         _HTML = """<html><body><h1>HTML</h1></body></html>"""
00993 
00994         site = DummySite('site').__of__(self.app)
00995         site.setup_tool = DummyTool( 'setup_tool' )
00996         tool = site.setup_tool
00997         ctx = self._makeOne( tool, 'simple' )
00998 
00999         ctx.writeDataFile( FILENAME, _HTML, CONTENT_TYPE, 'sub1' )
01000 
01001         snapshot = tool.snapshots._getOb( 'simple' )
01002         sub1 = snapshot._getOb( 'sub1' )
01003 
01004         self.assertEqual( len( sub1.objectIds() ), 1 )
01005         self.failUnless( FILENAME in sub1.objectIds() )
01006 
01007         template = sub1._getOb( FILENAME )
01008 
01009         self.assertEqual( template.getId(), FILENAME )
01010         self.assertEqual( template.meta_type, DTMLDocument.meta_type )
01011         self.assertEqual( template.read(), _HTML )
01012 
01013         ctx.writeDataFile( 'sub1/%s2' % FILENAME, _HTML, CONTENT_TYPE)
01014         self.assertEqual( len( sub1.objectIds() ), 2 )

Definition at line 960 of file test_context.py.

00960 
00961     def test_writeDataFile_unicode_xml( self ):
00962 
00963         from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
00964         FILENAME = 'simple.xml'
00965         CONTENT_TYPE = 'text/xml'
00966         _XML = u"""<?xml version="1.0"?><simple />"""
00967 
00968         site = DummySite('site').__of__(self.app)
00969         site.setup_tool = DummyTool( 'setup_tool' )
00970         tool = site.setup_tool
00971         ctx = self._makeOne( tool, 'simple' )
00972 
00973         ctx.writeDataFile( FILENAME, _XML, CONTENT_TYPE )
00974 
00975         snapshot = tool.snapshots._getOb( 'simple' )
00976 
00977         self.assertEqual( len( snapshot.objectIds() ), 1 )
00978         self.failUnless( FILENAME in snapshot.objectIds() )
00979 
00980         template = snapshot._getOb( FILENAME )
00981 
00982         self.assertEqual( template.getId(), FILENAME )
00983         self.assertEqual( template.meta_type, ZopePageTemplate.meta_type )
00984         self.assertEqual( template.read(), _XML )
00985         self.failIf( template.html() )


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