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

7 8
HERE = os.path.dirname(__file__)

9
class _ERP5(ERP5TypeTestSuite):
10
  _saved_test_id = "erp5_web_renderjs_ui_test:testFunctionalRJSInterfaceValidator"
11 12
  realtime_output = False
  enabled_product_list = ('CMFActivity', 'CMFCategory', 'ERP5', 'ERP5Catalog',
13
                          'ERP5Form',
14
                          'ERP5OOo', 'ERP5Security', 'ERP5Type',
15
                          'Formulator', 'ERP5Workflow',
16
                          'HBTreeFolder2', 'MailTemplates',
17
                          'PortalTransforms', 'TimerService', 'ZLDAPConnection', 
18
                          'ZLDAPMethods', 'ZMySQLDA', 'ZSQLCatalog', 'Zelenium')
19 20 21 22 23 24 25 26 27 28 29 30 31 32

  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))

33 34
  def _getAllTestList(self):
    test_list = []
35
    path = "%s/../" % HERE
36 37
    component_re = re.compile(".*/([^/]+)/TestTemplateItem/portal_components"
                              "/test\.[^.]+\.([^.]+).py$")
38
    for test_path in (
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        # glob('%s/product/Formulator/tests/test*.py' % path) +
        # glob('%s/product/ERP5Form/tests/test*.py' % path) +
        # ['%s/product/ERP5OOo/tests/testDeferredStyle.py' % path] +
        # ['%s/product/ERP5/tests/testXHTML.py' % path] +
        # ['%s/product/ERP5/tests/testERP5Core.py' % path] +
        # ['%s/product/ERP5/tests/testQueryModule.py' % path] +
        # ['%s/product/ERP5/tests/testBankReconciliation.py' % path] +
        # ['%s/product/ERP5Security/tests/testERP5Security.py' % path] +
        # ['%s/product/ERP5Type/tests/testFunctionalCore.py' % path] +
        # ['%s/product/ERP5Type/tests/testFunctionalKM.py' % path] +
        # ['%s/product/ERP5Type/tests/testFunctionalAnonymousSelection.py' % path] +
        # glob('%s/bt5/erp5_web/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_hal_json_style/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_token_login/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_trade_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_pdm_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_crm_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_item_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_deferred_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_accounting_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_accounting_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_bank_reconciliation_renderjs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_document_scanner_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_gadget_interface_validator_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_monitoring_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_travel_expense_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_officejs_support_request_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_officejs_afs_directory_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_configurator_standard/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_test_result/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_officejs_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_manifest_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_km_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_monaco_editor_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_web_project_ui_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_corporate_identity_test/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_run_my_doc*/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        # glob('%s/bt5/erp5_oauth*/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        glob('%s/bt5/erp5_web_js_style*/TestTemplateItem/portal_components/test.*.test*.py' % path) +
        []
      ):
84 85 86 87 88 89
      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
90 91 92 93 94 95 96
      product = test_path.split(os.sep)[-3]
      # don't test 3rd party products
      if product in ('PortalTransforms', 'MailTemplates', 'Zelenium'):
        continue
      test_list.append(test_case)
    return test_list

97
  def update(self):
98 99 100 101 102 103 104
    self.checkout('products', 'bt5')
    self.enableProducts()


class PERF(_ERP5):

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

107 108 109
class CloudPERF(_ERP5):

  def getTestList(self):
110
    return ['_testPystone', '_testSQLBench']
111

112 113 114 115 116
class ERP5(_ERP5):
  mysql_db_count = 3

  def getTestList(self):
    test_list = []
117 118 119 120
    for full_test_case in self._getAllTestList():
      test_case = (':' in full_test_case and full_test_case.split(':')[1]
                   or full_test_case)

121
      # skip some tests
122
      if test_case.find('Performance') > 0 \
123 124
         or test_case in ('testERP5LdapCatalog', # XXX (Ivan), until LDAP server is available this test will alway fail
                          # tests reading selenium tables from erp5.com
125
                          # not maintained
126
                          'testAccounting_l10n_fr_m9'
127
         ):
128
        continue
129
      test_list.append(full_test_case)
130 131
    return test_list

132 133 134 135
  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)
136
      if not status_dict['status_code']:
137
        status_dict = self.runUnitTest('--load', '--activity_node=2', full_test)
138
      return status_dict
139
    elif test.startswith('testFunctional'):
140
      return self._updateFunctionalTestResponse(self.runUnitTest(full_test))
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    elif test == 'testUpgradeInstanceWithOldDataFs':
      old_data_path = None
      for path in sys.path:
        if path.endswith('/erp5-bin'):
          old_data_path = os.path.join(path, 'test_data', test)
          if not os.path.isdir(old_data_path):
            return dict(
              status_code=-1,
              test_count=1,
              failure_count=1,
              stderr='%s does not exist or is not a directory' % old_data_path)

          break
      else:
        return dict(
          status_code=-1,
          test_count=1,
          failure_count=1,
          stderr='erp5-bin repository not found in %s' % '\n'.join(sys.path))

      instance_home = (self.instance and 'unit_test.%u' % self.instance
                       or 'unit_test')

      import shutil
165 166 167
      shutil.rmtree(instance_home, ignore_errors=True)

      os.makedirs(os.path.join(instance_home, 'var'))
168 169 170 171 172
      shutil.copyfile(os.path.join(old_data_path, 'Data.fs'),
                      os.path.join(instance_home, 'var', 'Data.fs'))
      shutil.copyfile(os.path.join(old_data_path, 'dump.sql'),
                      os.path.join(instance_home, 'dump.sql'))

173
      return self.runUnitTest('--load', '--portal_id=erp5', full_test)
174

175
    return super(ERP5, self).run(full_test)
176

177
  def _updateFunctionalTestResponse(self, status_dict):
178 179 180 181
    """ Convert the Unit Test output into more accurate information
        related to funcional test run.
    """
    # Parse relevant information to update response information
182 183 184
    try:
      summary, html_test_result = status_dict['stderr'].split("-"*79)[1:3]
    except ValueError:
185
      # In case of error when parse the file, preserve the original
186 187
      # informations. This prevents we have unfinished tests.
      return status_dict
188 189 190 191 192 193
    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'])
194
      status_dict['skip_count'] = int(group_dict['expected_failure'])
195 196
    return status_dict

197 198

class ERP5_simulation(_ERP5):
199 200

  def getTestList(self):
201 202 203 204 205 206 207 208 209 210 211 212
    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)

213
class ERP5_scalability(_ERP5):
214

215 216 217 218 219
  def getTestList(self):
    return ['createPerson', 'createSaleOrder', 'createWebPage']

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

221 222 223 224 225 226 227 228 229 230 231 232
  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
Xiaowu Zhang's avatar
Xiaowu Zhang committed
233 234 235 236 237 238

class ERP5_XHTML_Only(_ERP5):

  def _getAllTestList(self):
    path = sys.path[0]
    return ['%s/product/ERP5/tests/testXHTML.py' % path]
239 240 241 242 243 244

class FunctionalTests(ERP5):

  def _getAllTestList(self):
    return [x for x in super(FunctionalTests, self)._getAllTestList()
      if x.startswith('testFunctional') or ':testFunctional' in x]
245 246 247 248 249 250 251 252


class ERP5BusinessTemplateCodingStyleTestSuite(_ERP5):
  """Run coding style test on all business templates.
  """
  def getTestList(self):
    test_list = []
    for business_template_path in (
253 254 255 256 257 258 259 260 261 262 263 264
        glob('%s/../product/ERP5/bootstrap/erp5_*' % HERE) +
        glob('%s/../bt5/erp5_adm*' % HERE) +
        glob('%s/../bt5/erp5_*hal*' % HERE) +
        glob('%s/../bt5/erp5_*renderjs*' % HERE) +
        glob('%s/../bt5/erp5_*officejs*' % HERE) +
        glob('%s/../bt5/erp5_web*' % HERE) +
        glob('%s/../bt5/erp5_configu*' % HERE) +
        glob('%s/../bt5/erp5_upgrader*' % HERE) +
        glob('%s/../bt5/erp5_corporate_identity*' % HERE) +
        glob('%s/../bt5/erp5_run_my_doc*' % HERE) +
        []
      ):
265 266 267 268 269 270 271 272 273 274
      # we skip coding style check for business templates having this marker
      # property. Since the property is not exported (on purpose), modified business templates
      # will be candidate for coding style test again.
      if os.path.isdir(business_template_path) and \
              not os.path.exists(os.path.join(business_template_path, 'bt/skip_coding_style_test')):
        test_list.append(os.path.basename(business_template_path))
    return test_list

  def run(self, full_test):
    return self.runUnitTest('CodingStyleTest', TESTED_BUSINESS_TEMPLATE=full_test)
275

276 277 278 279 280 281 282 283
  def getLogDirectoryPath(self, *args, **kw):
    log_directory = os.path.join(
        self.log_directory,
        '{}-{}'.format(args[-1] , kw['TESTED_BUSINESS_TEMPLATE']))
    os.mkdir(log_directory)
    return log_directory


284 285 286 287 288 289 290 291
class RJS_Only(_ERP5):
  def getTestList(self):
    rjs_officejs_bt_list = ["erp5_officejs_",
                            "renderjs_ui_test",
                            "erp5_monaco_editor_ui_test",
                            "erp5_travel_expense_ui_test",
                            "erp5_gadget_interface_validator_ui_test",
                            "erp5_hal_json_style"]
292
    return [test for test in self._getAllTestList() if any(test.find(bt)>-1 for bt in rjs_officejs_bt_list)]