__init__.py 6.21 KB
Newer Older
1 2
from glob import glob
import os, subprocess, re
3 4
# test_suite is provided by 'run_test_suite'
from test_suite import ERP5TypeTestSuite
Sebastien Robin's avatar
Sebastien Robin committed
5
import sys
6 7 8 9

class _ERP5(ERP5TypeTestSuite):
  realtime_output = False
  enabled_product_list = ('CMFActivity', 'CMFCategory', 'ERP5', 'ERP5Catalog',
10
                          'ERP5eGovSecurity', 'ERP5Form',
11
                          'ERP5OOo', 'ERP5Security', 'ERP5SyncML', 'ERP5Type',
12
                          'ERP5VCS', 'ERP5Wizard', 'Formulator', 'ERP5Workflow',
13 14
                          'ERP5Configurator','HBTreeFolder2', 'MailTemplates', 
                          'PortalTransforms', 'TimerService', 'ZLDAPConnection', 
15
                          'ZLDAPMethods', 'ZMySQLDA', 'ZSQLCatalog', 'Zelenium')
16 17 18 19 20 21 22 23 24 25 26 27 28 29

  def enableProducts(self):
    product_set = set(self.enabled_product_list)
    try:
      dir_set = set(os.walk('Products').next()[1])
      for product in dir_set - product_set:
        os.unlink(os.path.join('Products', product))
      product_set -= dir_set
    except StopIteration:
      os.mkdir('Products')
    for product in product_set:
      os.symlink(os.path.join('..', 'products', product),
                 os.path.join('Products', product))

30 31
  def _getAllTestList(self):
    test_list = []
32 33 34
    path = sys.path[0]
    component_re = re.compile(".*/([^/]+)/TestTemplateItem/portal_components"
                              "/test\.[^.]+\.([^.]+).py$")
35
    for test_path in (
36 37 38 39 40 41 42 43 44
        glob('%s/product/*/tests/test*.py' % path) +
        glob('%s/bt5/*/TestTemplateItem/test*.py' % path) +
        glob('%s/bt5/*/TestTemplateItem/portal_components/test.*.test*.py' % path)):
      component_re_match = component_re.match(test_path)
      if component_re_match is not None:
        test_case = "%s:%s" % (component_re_match.group(1),
                               component_re_match.group(2))
      else:
        test_case = test_path.split(os.sep)[-1][:-3] # remove .py
45 46 47 48
      product = test_path.split(os.sep)[-3]
      # don't test 3rd party products
      if product in ('PortalTransforms', 'MailTemplates', 'Zelenium'):
        continue
49 50 51 52
      # ERP5TioSafe is disabled for now because it requires external programs
      # such as php and it has not been updated for Zope >= 2.12
      if product == 'ERP5TioSafe':
        continue
53 54 55
      test_list.append(test_case)
    return test_list

56
  def update(self):
57 58 59 60 61 62 63
    self.checkout('products', 'bt5')
    self.enableProducts()


class PERF(_ERP5):

  def getTestList(self):
64
    return [x for x in self._getAllTestList() if x.find('Performance')>0]
65

66 67 68
class CloudPERF(_ERP5):

  def getTestList(self):
69
    return ['_testPystone', '_testSQLBench']
70

71 72 73 74 75
class ERP5(_ERP5):
  mysql_db_count = 3

  def getTestList(self):
    test_list = []
76 77 78 79
    for full_test_case in self._getAllTestList():
      test_case = (':' in full_test_case and full_test_case.split(':')[1]
                   or full_test_case)

80
      # skip some tests
81 82 83 84
      if test_case.startswith('testLive') or test_case.startswith('testVifib') \
         or test_case.find('Performance') > 0 \
         or test_case in ('testERP5LdapCatalog', # XXX (Ivan), until LDAP server is available this test will alway fail
                          # tests reading selenium tables from erp5.com
85
                          # not maintained
86 87 88
                          'testFunctionalConfigurator',
                          'testFunctionalConfiguratorConsulting',
                          'testERP5eGov',
89 90 91 92
                          'testAccounting_l10n_fr_m9',
                          # Not a test
                          'testERP5SyncMLMixin'
         ):
93
        continue
94
      test_list.append(full_test_case)
95 96
    return test_list

97 98 99 100
  def run(self, full_test):
    test = ':' in full_test and full_test.split(':')[1] or full_test
    if test in ('testConflictResolution', 'testInvalidationBug'):
      status_dict = self.runUnitTest('--save', full_test)
101
      if not status_dict['status_code']:
102
        status_dict = self.runUnitTest('--load', '--activity_node=2', full_test)
103
      return status_dict
104
    if test.startswith('testFunctional'):
105 106
      return self._updateFunctionalTestResponse(self.runUnitTest(full_test))
    return super(ERP5, self).run(full_test)
107

108
  def _updateFunctionalTestResponse(self, status_dict):
109 110 111 112
    """ Convert the Unit Test output into more accurate information
        related to funcional test run.
    """
    # Parse relevant information to update response information
113 114 115
    try:
      summary, html_test_result = status_dict['stderr'].split("-"*79)[1:3]
    except ValueError:
116
      # In case of error when parse the file, preserve the original
117 118
      # informations. This prevents we have unfinished tests.
      return status_dict
119 120 121 122 123 124
    status_dict['html_test_result'] = html_test_result
    search = self.FTEST_PASS_FAIL_RE.search(summary)
    if search:
      group_dict = search.groupdict()
      status_dict['failure_count'] = int(group_dict['failures'])
      status_dict['test_count'] = int(group_dict['total'])
125
      status_dict['skip_count'] = int(group_dict['expected_failure'])
126 127
    return status_dict

128 129

class ERP5_simulation(_ERP5):
130 131

  def getTestList(self):
132 133 134 135 136 137 138 139 140 141 142 143
    p = subprocess.Popen(('grep', '-lr', '--include=test*.py',
                          '-e', '@newSimulationExpectedFailure',
                          '-e', 'erp5_report_new_simulation_failures',
                          'Products/ERP5/tests'),
                         stdout=subprocess.PIPE)
    return sorted(os.path.basename(x)[:-3]
                  for x in p.communicate()[0].splitlines())

  def runUnitTest(self, *args, **kw):
    return super(ERP5_simulation, self).runUnitTest(
      erp5_report_new_simulation_failures='1', *args, **kw)

144
class ERP5_scalability(_ERP5):
145

146 147 148 149 150
  def getTestList(self):
    return ['createPerson', 'createSaleOrder', 'createWebPage']

  def getTestPath(self):
    return 'erp5/util/benchmark/examples/'
151

152 153 154 155 156 157 158 159 160 161 162 163
  def getUsersFilePath(self):
    return 'erp5/util/benchmark/examples/scalabilityUsers'

  def getUserNumber(self, test_number):
    return [45, 135, 170, 220, 250][test_number]

  # Test duration in seconds
  def getTestDuration(self, test_number):
    return 60*10

  def getTestRepetition(self, test_number):
    return 3
164 165 166 167 168 169

class ERP5_XHTML_Only(_ERP5):

  def _getAllTestList(self):
    path = sys.path[0]
    return ['%s/product/ERP5/tests/testXHTML.py' % path]