Back to index

plone3  3.1.7
layer.py
Go to the documentation of this file.
00001 from AccessControl.SecurityManagement import newSecurityManager
00002 from Testing import ZopeTestCase
00003 from Products.PloneTestCase import PloneTestCase
00004 from Products.PloneTestCase.layer import PloneSite
00005 from StringIO import StringIO
00006 from base64 import decodestring
00007 from transaction import commit
00008 
00009 
00010 class PloneLinkintegrity(PloneSite):
00011 
00012     @classmethod
00013     def setUp(cls):
00014         app = ZopeTestCase.app()
00015         portal = app.plone
00016 
00017         # login as admin (copied from `loginAsPortalOwner`)
00018         uf = app.acl_users
00019         user = uf.getUserById(PloneTestCase.portal_owner).__of__(uf)
00020         newSecurityManager(None, user)
00021 
00022         # create sample content
00023         gif = 'R0lGODlhAQABAPAAAPj8+AAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
00024         gif = StringIO(decodestring(gif))
00025         portal.invokeFactory('Document', id='doc1', title='Test Page 1',
00026             text='<html> <body> a test page </body> </html>')
00027         portal.invokeFactory('Document', id='doc2', title='Test Page 2',
00028             text='<html> <body> another test page </body> </html>')
00029         portal.invokeFactory('Image', id='image1', title='Test Image 1', image=gif)
00030         portal.invokeFactory('Image', id='image2', title='Test Image 2', image=gif)
00031         portal.invokeFactory('Image', id='image3', title='Test Image 3', image=gif)
00032         portal.invokeFactory('File', id='file1', title='Test File 1', file=gif)
00033         portal.invokeFactory('Folder', id='folder1', title='Test Folder 1')
00034         portal.folder1.invokeFactory('Document', id='doc3', title='Test Page 3',
00035             text='<html> <body> a test page in a subfolder </body> </html>')
00036         portal.folder1.invokeFactory('Document', id='doc4', title='Test Page 4',
00037             text='<html> <body> another test page </body> </html>')
00038         portal.folder1.invokeFactory('Document', id='doc5', title='Test Page 5',
00039             text='<html> <body> another test page </body> </html>')
00040 
00041         # Unmark the creation flag so any calls processForm will not
00042         # rename our content objects.  This is mainly for getting the
00043         # tests running in combination with LinguaPlone.
00044         portal.doc1.unmarkCreationFlag()
00045         portal.doc2.unmarkCreationFlag()
00046         portal.image1.unmarkCreationFlag()
00047         portal.image2.unmarkCreationFlag()
00048         portal.image3.unmarkCreationFlag()
00049         portal.file1.unmarkCreationFlag()
00050         portal.folder1.unmarkCreationFlag()
00051         portal.folder1.doc3.unmarkCreationFlag()
00052         portal.folder1.doc4.unmarkCreationFlag()
00053         portal.folder1.doc5.unmarkCreationFlag()
00054 
00055         # starting with 2.10.4 product initialization gets delayed for
00056         # instance startup and is never called when running tests;  hence
00057         # we have to initialize the package method manually...
00058         from OFS.Application import install_package
00059         import plone.app.linkintegrity
00060         install_package(app, plone.app.linkintegrity, plone.app.linkintegrity.initialize)
00061 
00062         # create a starting point for the tests...
00063         commit()
00064         ZopeTestCase.close(app)
00065 
00066     @classmethod
00067     def tearDown(cls):
00068         app = ZopeTestCase.app()
00069         portal = app.plone
00070 
00071         # login as admin (copied from `loginAsPortalOwner`)
00072         uf = app.acl_users
00073         user = uf.getUserById(PloneTestCase.portal_owner).__of__(uf)
00074         newSecurityManager(None, user)
00075 
00076         # remove sample content
00077         ids = 'doc1', 'doc2', 'image1', 'image2', 'image3', 'folder1', 'file1'
00078         portal.manage_delObjects(ids=list(ids))
00079 
00080         # commit the cleanup...
00081         commit()
00082         ZopeTestCase.close(app)
00083 
00084