Back to index

plone3  3.1.7
zcheck.py
Go to the documentation of this file.
00001 #
00002 # To run the ZChecker on all skins in this instance type
00003 #
00004 # $ ./bin/zopectl test -q --nowarn -s Products.CMFPlone --tests-pattern zcheck
00005 #
00006 
00007 __version__ = '0.3.0'
00008 
00009 from Testing import ZopeTestCase
00010 from Testing.ZopeTestCase import _print
00011 
00012 ZopeTestCase.installProduct('PlacelessTranslationService')
00013 ZopeTestCase.installProduct('ZChecker')
00014 
00015 from Products.CMFPlone.tests import PloneTestCase
00016 from Products.PloneTestCase import setup
00017 
00018 ignoredSkinLayers = ['portal_skins/kupu_plone', 'portal_skins/kupu_tests']
00019 
00020 ignoredObjectIds = ['rssBody', 'RSS', 'rss_template', 'search_rss',
00021                     'test_ecmascripts', 'kupu_wysiwyg_support',
00022                     # There is no DTD for the pdf topic stuff
00023                     'atct_topic_pdf', 'atct_topic_pdf_template']
00024 
00025 if setup.PLONE30:
00026     # Ignore until it is no longer DTML
00027     ignoredObjectIds += ['mail_password_template']
00028 
00029 
00030 class TestSkins(PloneTestCase.PloneTestCase):
00031     # Note: This looks like a unit test but isn't
00032 
00033     def afterSetUp(self):
00034         factory = self.portal.manage_addProduct['ZChecker']
00035         factory.manage_addZChecker('zchecker')
00036         self.portal.zchecker.setIgnoreObjectIds(ignoredObjectIds)
00037         import sys
00038         self.verbose = not '-q' in sys.argv
00039 
00040     def testSkins(self):
00041         '''Runs the ZChecker on skins'''
00042         dirs = self.portal.portal_skins.objectValues()
00043         for dir in dirs:
00044             # filter out certain skin layers
00045             if self._skinpath(dir) not in ignoredSkinLayers:
00046                 results = self.portal.zchecker.checkObjects(dir.objectValues())
00047                 for result in results:
00048                     self._report(result)
00049         if self.verbose:
00050             _print('\n')
00051 
00052     def _report(self, result):
00053         msg = result['msg']
00054         obj = result['obj']
00055         if msg:
00056             if self.verbose:
00057                 _print('\n')
00058             _print('------\n%s\n' % self._skinpath(obj))
00059             for line in msg:
00060                 _print('%s\n' % line)
00061         else:
00062             if self.verbose:
00063                 _print('.')
00064 
00065     def _skinpath(self, obj):
00066         return '/'.join(obj.getPhysicalPath()[2:])
00067 
00068     def _filepath(self, obj):
00069         filepath = getattr(obj, 'getObjectFSPath', None)
00070         if filepath is not None:
00071             return filepath()
00072 
00073 
00074 def test_suite():
00075     from unittest import TestSuite, makeSuite
00076     suite = TestSuite()
00077     suite.addTest(makeSuite(TestSkins))
00078     return suite
00079