From b2429d501d8f1d40b1ae936e33bbf162c1d099cf Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Sun, 8 Sep 2013 19:40:54 +0900 Subject: [PATCH] ZODB Components: Test bootstrap is already done before even running the test. Therefore, all Test Components are now ERP5TypeLiveTestCase. For backward compatibility sake, just modify Test Component class bases to ERP5TypeLiveTestCase, likewise runLiveTest. This means that tests ran through runUnitTest and from Live Tests ERP5 UI would behave exactly the same, contrary to the implementation before Test Components. Also, move a method called in one of ERP5TypeTypeMixin method from ERP5TypeTestCaseCommandLine. --- product/ERP5Type/tests/ERP5TypeTestCase.py | 103 +++++++++++---------- product/ERP5Type/tests/runUnitTest.py | 5 + 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index 5b1f7d1f2e..b98b54390b 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -483,6 +483,58 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): DeprecationWarning) return self.createUserAssignment(user, assignment_kw) + @staticmethod + def _getBTPathAndIdList(template_list): + bootstrap_path = os.environ.get('erp5_tests_bootstrap_path') or \ + ERP5Site.getBootstrapDirectory() + bt5_path = os.environ.get('erp5_tests_bt5_path') + if bt5_path: + bt5_path_list = bt5_path.split(',') + bt5_path_list += [os.path.join(path, "*") for path in bt5_path_list] + else: + bt5_path = os.path.join(instancehome, 'bt5') + bt5_path_list = bt5_path, os.path.join(bt5_path, '*') + + def search(path, template): + urltype, url = urllib.splittype(path + '/' + template) + if urltype == 'http': + host, selector = urllib.splithost(url) + user_passwd, host = urllib.splituser(host) + host = urllib.unquote(host) + h = httplib.HTTP(host) + h.putrequest('HEAD', selector) + h.putheader('Host', host) + if user_passwd: + h.putheader('Authorization', + 'Basic %s' % base64.b64encode(user_passwd).strip()) + h.endheaders() + errcode, errmsg, headers = h.getreply() + if errcode == 200: + return urltype + ':' + url + else: + path_list = glob(os.path.join(path, template)) + if path_list: + return path_list[0] + + not_found_list = [] + new_template_list = [] + for template in template_list: + id = template.split('/')[-1] + for path in bt5_path_list: + path = search(path, template) or search(path, template + '.bt5') + if path: + break + else: + path = os.path.join(bootstrap_path, template) + if not os.path.exists(path): + not_found_list.append(template) + continue + new_template_list.append((path, id)) + if not_found_list: + raise RuntimeError("Following BT can't be found on your system : %s" + % ', '.join(not_found_list)) + return new_template_list + def setupAutomaticBusinessTemplateRepository(self, accept_public=True, searchable_business_template_list=None): # Try to setup some valid Repository List by reusing ERP5TypeTestCase API. @@ -745,57 +797,6 @@ class ERP5TypeCommandLineTestCase(ERP5TypeTestCaseMixin): """ return 0 - @staticmethod - def _getBTPathAndIdList(template_list): - bootstrap_path = os.environ.get('erp5_tests_bootstrap_path') or \ - ERP5Site.getBootstrapDirectory() - bt5_path = os.environ.get('erp5_tests_bt5_path') - if bt5_path: - bt5_path_list = bt5_path.split(',') - else: - bt5_path = os.path.join(instancehome, 'bt5') - bt5_path_list = bt5_path, os.path.join(bt5_path, '*') - - def search(path, template): - urltype, url = urllib.splittype(path + '/' + template) - if urltype == 'http': - host, selector = urllib.splithost(url) - user_passwd, host = urllib.splituser(host) - host = urllib.unquote(host) - h = httplib.HTTP(host) - h.putrequest('HEAD', selector) - h.putheader('Host', host) - if user_passwd: - h.putheader('Authorization', - 'Basic %s' % base64.b64encode(user_passwd).strip()) - h.endheaders() - errcode, errmsg, headers = h.getreply() - if errcode == 200: - return urltype + ':' + url - else: - path_list = glob(os.path.join(path, template)) - if path_list: - return path_list[0] - - not_found_list = [] - new_template_list = [] - for template in template_list: - id = template.split('/')[-1] - for path in bt5_path_list: - path = search(path, template) or search(path, template + '.bt5') - if path: - break - else: - path = os.path.join(bootstrap_path, template) - if not os.path.exists(path): - not_found_list.append(template) - continue - new_template_list.append((path, id)) - if not_found_list: - raise RuntimeError("Following BT can't be found on your system : %s" - % ', '.join(not_found_list)) - return new_template_list - def manuallyInstallBusinessTemplate(self, *template_list): new_template_list = self._getBTPathAndIdList(template_list) light_install = self.enableLightInstall() diff --git a/product/ERP5Type/tests/runUnitTest.py b/product/ERP5Type/tests/runUnitTest.py index 7dab8c2606..eea06bc7b7 100755 --- a/product/ERP5Type/tests/runUnitTest.py +++ b/product/ERP5Type/tests/runUnitTest.py @@ -303,6 +303,11 @@ class ERP5TypeTestLoader(unittest.TestLoader): from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeLiveTestCase import ERP5TypeLiveTestCase + # Bootstrap has been done in loadTestsFromNames, so the test can now + # be loaded like any Live Test on a real instance + if ERP5TypeLiveTestCase not in ERP5TypeTestCase.__bases__: + ERP5TypeTestCase.__bases__ = ERP5TypeLiveTestCase, + # TestLoader() does not perform any import so import the Module manually module = __import__('erp5.component.test', fromlist=['erp5.component.test'], -- GitLab