Back to index

plone3  3.1.7
testStyleInstallation.py
Go to the documentation of this file.
00001 #
00002 # Unit Tests for the style install and uninstall methods
00003 #
00004 
00005 import os, sys
00006 
00007 from Products.PloneTestCase import PloneTestCase
00008 
00009 PROJECTNAME = 'NuPlone'
00010 
00011 PloneTestCase.installProduct(PROJECTNAME)
00012 PloneTestCase.setupPloneSite(products=[PROJECTNAME])
00013 
00014 class testSkinsTool(PloneTestCase.PloneTestCase):
00015 
00016     def afterSetUp(self):
00017         self.tool = getattr(self.portal, 'portal_skins')
00018 
00019     def testSkinSelectionCreated(self):
00020         """Test if a new skin exists in portal_skins."""
00021         for skin_selection in SKINSELECTIONS:
00022             self.failUnless(
00023                 skin_selection['name'] in self.tool.getSkinSelections())
00024 
00025     def testSkinPaths(self):
00026         """Test if the skin layers in the new skin were correctly added."""
00027         skinsfoldernames = getSkinsFolderNames(GLOBALS)
00028         skins_dict = {}
00029         for skin in SKINSELECTIONS:
00030             skins_dict[skin['name']] = skin.get('layers', skinsfoldernames)
00031         for selection, layers in self.tool.getSkinPaths():
00032             if skins_dict.has_key(selection):
00033                 for specific_layer in skins_dict[selection]:
00034                     self.failUnless(specific_layer in layers)
00035             else:
00036                 for foldername in skinsfoldernames:
00037                     self.failIf(foldername in layers)
00038 
00039     def testSkinSelection(self):
00040         """Test if the new skin was selected as default one."""
00041         if SELECTSKIN:
00042             self.assertEqual(self.tool.getDefaultSkin(), DEFAULTSKIN)
00043 
00044     def testSkinFlexibility(self):
00045         """Test if the users can choose their skin."""
00046         self.assertEqual(self.tool.getAllowAny(), ALLOWSELECTION)
00047 
00048     def testCookiePersistance(self):
00049         """Test if the skin choice is peristant between sessions."""
00050         self.assertEqual(bool(self.tool.getCookiePersistence()),
00051                                                         PERSISTENTCOOKIE)
00052 
00053 class testResourceRegistrations(PloneTestCase.PloneTestCase):
00054 
00055     def afterSetUp(self):
00056         self.qitool      = getattr(self.portal, 'portal_quickinstaller')
00057         self.csstool     = getattr(self.portal, 'portal_css')
00058         self.jstool      = getattr(self.portal, 'portal_javascripts')
00059         product_settings = getattr(self.qitool, PROJECTNAME)
00060         self.stylesheets = product_settings.resources_css
00061         self.javascripts = product_settings.resources_js
00062 
00063     def testStylesheetsInstalled(self):
00064         """Test if new stylesheets were added to portal_css."""
00065         stylesheetids = self.csstool.getResourceIds()
00066         for css in STYLESHEETS:
00067             self.failUnless(css['id'] in stylesheetids)
00068 
00069     def testStylesheetProperties(self):
00070         """Test if new stylesheets have correct parameters."""
00071         for config in STYLESHEETS:
00072             res = self.csstool.getResource(config['id'])
00073             for key in [key for key in config.keys() if key != 'id']:
00074                 self.assertEqual(res._data[key], config[key])
00075 
00076     def testStylesheetsUpdated(self):
00077         """Test if existing stylesheets were correctly updated."""
00078         for config in [c for c in STYLESHEETS
00079                        if c['id'] not in self.stylesheets]:
00080             resource = self.csstool.getResource(config['id'])
00081             for key in [k for k in config.keys() if k != 'id']:
00082                 self.failUnless(resource._data.has_key('original_'+key))
00083 
00084     def testJavascriptsInstalled(self):
00085         """Test if new javascripts were added to portal_javascripts."""
00086         javascriptids = self.jstool.getResourceIds()
00087         for js in JAVASCRIPTS:
00088             self.failUnless(js['id'] in javascriptids)
00089 
00090     def testMemberStylesheetProperties(self):
00091         """Test if new javascripts have correct parameters."""
00092         for config in JAVASCRIPTS:
00093             res = self.jstool.getResource(config['id'])
00094             for key in [key for key in config.keys() if key != 'id']:
00095                 self.assertEqual(res._data[key], config[key])
00096 
00097     def testJavascriptsUpdated(self):
00098         """Test if existing javascripts were correctly updated."""
00099         for config in [c for c in JAVASCRIPTS
00100                        if c['id'] not in self.javascripts]:
00101             resource = self.jstool.getResource(config['id'])
00102             for key in [k for k in config.keys() if k != 'id']:
00103                 self.failUnless(resource._data.has_key('original_'+key))
00104 
00105 class testDisplayViewsRegistration(PloneTestCase.PloneTestCase):
00106 
00107     def afterSetUp(self):
00108         self.ttool = getattr(self.portal, 'portal_types')
00109 
00110     def testDisplayViewsRegistered(self):
00111         """Test if additional display views were added to specified types."""
00112         if DISPLAY_VIEWS:
00113             for pt, views in DISPLAY_VIEWS.items():
00114                 FTI = getattr(self.ttool, pt)
00115                 registered_views = FTI.view_methods
00116                 for view in views:
00117                     self.failUnless(view in registered_views)
00118 
00119 
00120 class testUninstall(PloneTestCase.PloneTestCase):
00121 
00122     def afterSetUp(self):
00123         """Test if ."""
00124         self.qitool      = getattr(self.portal, 'portal_quickinstaller')
00125         self.skinstool   = getattr(self.portal, 'portal_skins')
00126         self.csstool     = getattr(self.portal, 'portal_css')
00127         self.jstool      = getattr(self.portal, 'portal_javascripts')
00128         product_settings = getattr(self.qitool, PROJECTNAME)
00129         self.stylesheets = product_settings.resources_css
00130         self.javascripts = product_settings.resources_js
00131         self.qitool.uninstallProducts(products=[PROJECTNAME])
00132         self.ttool = getattr(self.portal, 'portal_types')
00133 
00134     def testProductUninstalled(self):
00135         """Test if the product was uninstalled."""
00136         self.failIf(self.qitool.isProductInstalled(PROJECTNAME))
00137 
00138     def testSkinSelectionDeleted(self):
00139         """Test if the skin selection was removed from portal_skins."""
00140         skin_selections = self.skinstool.getSkinSelections()
00141         for skin in SKINSELECTIONS:
00142             self.failIf(skin['name'] in skin_selections)
00143 
00144     def testDefaultSkinChanged(self):
00145         """Test if default skin is back to old value or default Plone."""
00146         default_skin = self.skinstool.getDefaultSkin()
00147         if RESETSKINTOOL:
00148             self.assertEqual(default_skin, 'Plone Default')
00149         else:
00150             if DEFAULTSKIN:
00151                 for skin in SKINSELECTIONS:
00152                     if skin['name'] == DEFAULTSKIN:
00153                         self.assertEqual(default_skin, skin['base'])
00154             else:
00155                 self.assertEqual(default_skin, SKINSELECTIONS[0]['base'])
00156 
00157     def testResetSkinFlexibility(self):
00158         """Test if the users still can choose their skin."""
00159         allow_any = self.skinstool.getAllowAny()
00160         if RESETSKINTOOL:
00161             self.failIf(allow_any)
00162         else:
00163             self.assertEqual(allow_any, ALLOWSELECTION)
00164 
00165     def testResetCookiePersistance(self):
00166         """Test if the skin choice is still peristant between sessions."""
00167         cookie_peristence = self.skinstool.getCookiePersistence()
00168         if RESETSKINTOOL:
00169             self.failIf(cookie_peristence)
00170         else:
00171             self.assertEqual(cookie_peristence, PERSISTENTCOOKIE)
00172 
00173     def testStylesheetsUninstalled(self):
00174         """Test if added stylesheets were removed from portal_css."""
00175         resourceids = self.csstool.getResourceIds()
00176         for css in self.stylesheets:
00177             self.failIf(css in resourceids)
00178 
00179     def testResetDefaultStylesheets(self):
00180         """Test if values were reverted in existing stylesheets."""
00181         for config in [c for c in STYLESHEETS
00182                        if c['id'] not in self.stylesheets]:
00183             resource = self.csstool.getResource(config['id'])
00184             for key in [k for k in config.keys() if k != 'id']:
00185                 self.failIf(resource._data.has_key('original_'+key))
00186 
00187     def testJavascriptsUninstalled(self):
00188         """Test if added javascripts were removed from portal_js."""
00189         resourceids = self.jstool.getResourceIds()
00190         for js in self.javascripts:
00191             self.failIf(js in resourceids)
00192 
00193     def testResetDefaultJavascripts(self):
00194         """Test if values were reverted in existing javascripts."""
00195         for config in [c for c in JAVASCRIPTS
00196                        if c['id'] not in self.javascripts]:
00197             resource = self.jstool.getResource(config['id'])
00198             for key in [k for k in config.keys() if k != 'id']:
00199                 self.failIf(resource._data.has_key('original_'+key))
00200 
00201     def testDisplayViewsUnregistered(self):
00202         """Make sure additional Display Views were removed"""
00203         if DISPLAY_VIEWS:
00204             for pt, views in DISPLAY_VIEWS.items():
00205                 FTI = getattr(self.ttool, pt)
00206                 registered_views = FTI.view_methods
00207                 for view in views:
00208                     self.failIf(view in registered_views)
00209 
00210 if __name__ == '__main__':
00211     framework()
00212 else:
00213     import unittest
00214     def test_suite():
00215         suite = unittest.TestSuite()
00216         suite.addTest(unittest.makeSuite(testSkinsTool))
00217         suite.addTest(unittest.makeSuite(testResourceRegistrations))
00218         suite.addTest(unittest.makeSuite(testDisplayViewsRegistration))
00219         suite.addTest(unittest.makeSuite(testUninstall))
00220         return suite