Back to index

plone3  3.1.7
testFactoryTool.py
Go to the documentation of this file.
00001 #
00002 # Exportimport adapter tests
00003 #
00004 
00005 import os, sys
00006 if __name__ == '__main__':
00007     execfile(os.path.join(sys.path[0], 'framework.py'))
00008 
00009 from Products.CMFPlone.tests import PloneTestCase
00010 from Products.CMFPlone.exportimport.tests.base import BodyAdapterTestCase
00011 
00012 from zope.app.component.hooks import setHooks, setSite
00013 from zope.component import getSiteManager
00014 from Products.CMFCore.interfaces import ITypesTool
00015 from Products.CMFPlone.FactoryTool import FactoryTool
00016 from Products.CMFPlone.setuphandlers import PloneGenerator
00017 from OFS.Folder import Folder
00018 
00019 _FACTORYTOOL_XML = """\
00020 <?xml version="1.0"?>
00021 <object name="portal_factory" meta_type="Plone Factory Tool">
00022  <factorytypes>
00023   <type portal_type="Folder"/>
00024   <type portal_type="Document"/>
00025  </factorytypes>
00026 </object>
00027 """
00028 
00029 
00030 class DummyTypesTool(Folder):
00031 
00032     id = 'portal_types'
00033     meta_type = 'Dummy Types Tool'
00034 
00035     def listContentTypes(self):
00036         return ('Folder', 'Document')
00037 
00038 
00039 class PortalFactoryXMLAdapterTests(BodyAdapterTestCase):
00040 
00041     def _getTargetClass(self):
00042         from Products.CMFPlone.exportimport.factorytool \
00043                     import PortalFactoryXMLAdapter
00044         return PortalFactoryXMLAdapter
00045 
00046     def _populate(self, obj):
00047         obj.manage_setPortalFactoryTypes(listOfTypeIds=('Folder', 'Document'))
00048 
00049     def setUp(self):
00050         setHooks()
00051         self.site = Folder('site')
00052         gen = PloneGenerator()
00053         gen.enableSite(self.site)
00054         setSite(self.site)
00055         sm = getSiteManager()
00056         self.site.portal_types = DummyTypesTool()
00057         sm.registerUtility(self.site.portal_types, ITypesTool)
00058         self.site.portal_factory = FactoryTool()
00059 
00060         self._obj = self.site.portal_factory
00061         self._BODY = _FACTORYTOOL_XML
00062 
00063 
00064 def test_suite():
00065     from unittest import TestSuite, makeSuite
00066     suite = TestSuite()
00067     suite.addTest(makeSuite(PortalFactoryXMLAdapterTests))
00068     return suite
00069 
00070 if __name__ == '__main__':
00071     framework()
00072