8. base.py from Testing import ZopeTestCase ZopeTestCase.installProduct('My Product') from Products.PloneTestCase.PloneTestCase import PloneTestCase from Products.PloneTestCase.PloneTestCase import FunctionalTestCase from Products.PloneTestCase.PloneTestCase import setupPloneSite setupPloneSite(products=['My Product']) class MyProductTestCase(PloneTestCase): """We use this base class for all the tests in this package. If necessary, we can put common utility or setup code in here. This applies to unit test cases. """ class MyProductFunctionalTestCase(FunctionalTestCase): """We use this class for functional integration tests that use doctest syntax. Again, we can put basic common utility or setup code in here. """
9. my_test.py import os, sys if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) from base import MyProductTestCase class TestClass(MyProductTestCase): """Tests for this and that...""" ... def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() ... suite.addTest(makeSuite(TestClass)) ... return suite if __name__ == '__main__': framework()
10. Instalación de skins y recursos class TestInstallation(MyProductTestCase): """Ensure product is properly installed""" def afterSetUp(self): ... self.skins = self.portal.portal_skins self.csstool = self.portal.portal_css self.jstool = self.portal.portal_javascripts ... def testSkinLayersInstalled(self): """Verifies the skin layer was registered""" self.failUnless('my_product_skin' in self.skins.objectIds()) def testCssInstalled(self): """Verifies the associated CSS file was registered""" stylesheetids = self.csstool.getResourceIds() self.failUnless('my_css_id' in stylesheetids) def testJavascriptsInstalled(self): """Verifies the associated JavaScript file was registered""" javascriptids = self.jstool.getResourceIds() self.failUnless('my_js_id' in javascriptids)
11. Instalación de tipos de contenido class TestInstallation(MyProductTestCase): """Ensure product is properly installed""" def afterSetUp(self): ... self.types = self.portal.portal_types self.factory = self.portal.portal_factory ... def testTypesInstalled(self): """Verifies the content type was installed""" self.failUnless('My Type' in self.types.objectIds()) def testPortalFactorySetup(self): """Verifies the content type was registered in the portal factory. The portal factory ensures that new objects are created in a well-behaved fashion. """ self.failUnless('My Type' in self.factory.getFactoryTypes())
12. Instalación de tools y configlets class TestInstallation(MyProductTestCase): """Ensure product is properly installed""" def afterSetUp(self): ... self.config = self.portal.portal_controlpanel ... def testToolInstalled(self): """Verifies a tool was installed""" self.failUnless(getattr(self.portal, 'my_tool', None) is not None) def testConfigletInstalled(self): """Verifies a configlet was installed""" configlets = list(self.config.listActions()) self.failUnless('my_configlet_id' in configlets)
13. Verificando recursos de Kupu class TestInstallation(MyProductTestCase): """Ensure product is properly installed""" def afterSetUp(self): ... self.kupu = self.portal.kupu_library_tool ... def testKupuResourcesSetup(self): """Verifies the content type can be linked inside Kupu""" linkable = self.kupu.getPortalTypesForResourceType('linkable') self.failUnless('My Type' in linkable)
14. Verificando otras propiedades class TestInstallation(MyProductTestCase): """Ensure product is properly installed""" def afterSetUp(self): ... self.props = self.portal.portal_properties ... def testDefaultPageTypes(self): """Verifies the content type can be used as the default page in a container object like a folder. """ self.failUnless('My Type' in self.props.site_properties.getProperty('default_page_types'))
15. Desinstalación del producto class TestUninstall(MyProductTestCase): """Ensure product is properly uninstalled""" def afterSetUp(self): ... self.qitool = self.portal.portal_quickinstaller self.qitool.uninstallProducts(products=['My Product']) ... def testProductUninstalled(self): """Verifies the product was uninstalled""" self.failIf(self.qitool.isProductInstalled('My Product'))
16. Implementación from Interface.Verify import verifyObject from Products.ATContentTypes.interface import IATContentType from Products.MyProduct.interfaces import IMyProduct class TestContentType(MyProductTestCase): """Ensure content type implementation""" def afterSetUp(self): self.folder.invokeFactory('My Type', 'mytype1') self.mytype1 = getattr(self.folder, 'mytype1') def testImplementsATContentType(self): """Verifies the object implements the base Archetypes interface""" iface = IATContentType self.failUnless(iface.providedBy(self.mytype1)) self.failUnless(verifyObject(iface, self.mytype1)) def testImplementsMyType(self): """Verifies the object implements the content type interface""" iface = IMyType self.failUnless(iface.providedBy(self.mytype1)) self.failUnless(verifyObject(iface, self.mytype1))
17. Creación y edición de contenido class TestContentCreation(MyProductTestCase): """Ensure content type can be created and edited""" def afterSetUp(self): self.folder.invokeFactory('My Type', 'mytype1') self.mytype1 = getattr(self.folder, 'mytype1') def testCreateMyType(self): """Verifies the object has been created""" self.failUnless('mytype1' in self.folder.objectIds()) def testEditMyType(self): """Verifies the object can be properly edited""" self.mytype1.setTitle('A title') self.mytype1.setDescription('A description') ... self.assertEqual(self.mytype1.Title(), 'A title') self.assertEqual(self.mytype1.Description(), 'A description') ...
20. zope.testbrowser zope.testrecorder Es elegante y fácil de usar, pero no soporta JavaScript Permite grabar las pruebas en formato zope.testbrowser o Selenium