[Erp5-report] r32832 jp - in /erp5/trunk/products: ERP5/tests/ ERP5Type/tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Feb 19 07:32:02 CET 2010


Author: jp
Date: Fri Feb 19 07:32:01 2010
New Revision: 32832

URL: http://svn.erp5.org?rev=32832&view=rev
Log:
CodingStyleTestCase abstract base class implements testing of coding style methods. testERP5WebCodingStyle is an example of test which uses CodingStyleTestCase. 

Added:
    erp5/trunk/products/ERP5/tests/testERP5WebCodingStyle.py
    erp5/trunk/products/ERP5Type/tests/CodingStyleTestCase.py

Added: erp5/trunk/products/ERP5/tests/testERP5WebCodingStyle.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testERP5WebCodingStyle.py?rev=32832&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/tests/testERP5WebCodingStyle.py (added)
+++ erp5/trunk/products/ERP5/tests/testERP5WebCodingStyle.py [utf8] Fri Feb 19 07:32:01 2010
@@ -1,0 +1,51 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+#          Jean-Paul Smets <jp at 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

Added: erp5/trunk/products/ERP5Type/tests/CodingStyleTestCase.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/CodingStyleTestCase.py?rev=32832&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/CodingStyleTestCase.py (added)
+++ erp5/trunk/products/ERP5Type/tests/CodingStyleTestCase.py [utf8] Fri Feb 19 07:32:01 2010
@@ -1,0 +1,104 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+#          Jean-Paul Smets <jp at 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)))




More information about the Erp5-report mailing list