Commit 3d03f162 authored by Jean-Paul Smets's avatar Jean-Paul Smets

CodingStyleTestCase abstract base class implements testing of coding style...

CodingStyleTestCase abstract base class implements testing of coding style methods. testERP5WebCodingStyle is an example of test which uses CodingStyleTestCase. 

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32832 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 37a98eb9
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import unittest
from Products.ERP5Type.tests.CodingStyleTestCase import CodingStyleTestCase
class CodingStyle(CodingStyleTestCase):
"""
Check consistency of erp5_web business template code
"""
def getTitle(self):
return "erp5_web CodingStyle"
def getBusinessTemplateList(self):
"""
Return the list of required business templates.
"""
return ('erp5_base',
'erp5_web',
)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(CodingStyle))
return suite
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Testing import ZopeTestCase
from Acquisition import aq_base
class CodingStyleTestCase(ERP5TypeTestCase):
"""XXX
"""
run_all_test = 1
quiet = 0
manager_username = 'zope'
manager_password = 'zope'
website_id = 'test'
def getTitle(self):
"""
Override this method in implementation class.
"""
raise NotImplementedError
def getBusinessTemplateList(self):
"""
Return the list of required business templates.
Override this method in implementation class.
"""
raise NotImplementedError
def getTestedBusinessTemplateList(self):
"""
Return the list of business templates to be
checked for consistency. By default, return
the last business template of the
list of installed business templates.
"""
return self.getBusinessTemplateList()[-1:]
def afterSetUp(self):
portal = self.getPortal()
uf = portal.acl_users
uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], [])
self.login(self.manager_username)
self.portal_id = self.portal.getId()
def test_01_SkinCodingStyle(self, quiet=quiet, run=run_all_test):
"""
Find all skin items of business templates to be checked
and gather all consistency messages.
"""
if not run: return
if not quiet:
message = '\ntest_01_CodingStyle'
ZopeTestCase._print(message)
# Find the list if skins to test - we only test the last business template
portal_templates = self.getPortal().portal_templates
skin_id_list = []
for business_template in portal_templates.contentValues():
if business_template.getTitle() in self.getTestedBusinessTemplateList():
skin_id_list.extend(business_template.getTemplateSkinIdList())
# Init message list
message_list = []
# Test skins
portal_skins = self.getPortal().portal_skins
for skin_id in skin_id_list:
skin = portal_skins[skin_id]
for document in skin.objectValues():
if getattr(aq_base(document), 'checkConsistency', None) is not None:
message_list.extend(document.checkConsistency())
# Return results
if len(message_list):
raise self.failureException('\n'.join(map(lambda x: repr(x), message_list)))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment