Commit d78f98f7 authored by Jérome Perrin's avatar Jérome Perrin

LiveTest: set SERVER_URL in the test request so that tests run with same URL as the host

(cherry picked from commit 8fab4d97)
parent d452124f
...@@ -295,6 +295,7 @@ class Test(ERP5TypeTestCase): ...@@ -295,6 +295,7 @@ class Test(ERP5TypeTestCase):
debug = int(debug) and True or False debug = int(debug) and True or False
run_only = self._getCommaSeparatedParameterList(run_only) run_only = self._getCommaSeparatedParameterList(run_only)
verbosity = verbose and 2 or 1 verbosity = verbose and 2 or 1
request_server_url = self.REQUEST.get('SERVER_URL')
try: try:
live_test_running = True live_test_running = True
...@@ -304,6 +305,7 @@ class Test(ERP5TypeTestCase): ...@@ -304,6 +305,7 @@ class Test(ERP5TypeTestCase):
run_only=run_only, run_only=run_only,
debug=debug, debug=debug,
stream=global_stream, stream=global_stream,
request_server_url=request_server_url,
verbosity=verbosity) verbosity=verbosity)
except ImportError: except ImportError:
import traceback import traceback
......
...@@ -51,6 +51,7 @@ from Products.ERP5Type.tests import ProcessingNodeTestCase as\ ...@@ -51,6 +51,7 @@ from Products.ERP5Type.tests import ProcessingNodeTestCase as\
ProcessingNodeTestCaseModule ProcessingNodeTestCaseModule
ProcessingNodeTestCaseModule.patchActivityTool = lambda: None ProcessingNodeTestCaseModule.patchActivityTool = lambda: None
_request_server_url = None
class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
"""ERP5TypeLiveTestCase is the default class for *all* tests """ERP5TypeLiveTestCase is the default class for *all* tests
...@@ -109,6 +110,11 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin): ...@@ -109,6 +110,11 @@ class ERP5TypeLiveTestCase(ERP5TypeTestCaseMixin):
with patches._requests_lock: with patches._requests_lock:
patches._requests[thread.get_ident()] = request patches._requests[thread.get_ident()] = request
# Make live tests run under the same server URL than the host instance.
if _request_server_url:
request['SERVER_URL'] = _request_server_url
request._resetURLS()
self.portal = portal self.portal = portal
return portal return portal
...@@ -186,7 +192,7 @@ class ERP5TypeLiveTestLoader(ERP5TypeTestLoader): ...@@ -186,7 +192,7 @@ class ERP5TypeLiveTestLoader(ERP5TypeTestLoader):
return super(ERP5TypeLiveTestLoader, self).loadTestsFromName(name, return super(ERP5TypeLiveTestLoader, self).loadTestsFromName(name,
module) module)
def runLiveTest(test_list, verbosity=1, stream=None, **kw): def runLiveTest(test_list, verbosity=1, stream=None, request_server_url=None, **kw):
from Products.ERP5Type.tests.runUnitTest import DebugTestResult from Products.ERP5Type.tests.runUnitTest import DebugTestResult
from StringIO import StringIO from StringIO import StringIO
# Add path of the TestTemplateItem folder of the instance # Add path of the TestTemplateItem folder of the instance
...@@ -199,6 +205,9 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw): ...@@ -199,6 +205,9 @@ def runLiveTest(test_list, verbosity=1, stream=None, **kw):
product_test_list.extend(glob(os.path.join(product_path, '*', 'tests'))) product_test_list.extend(glob(os.path.join(product_path, '*', 'tests')))
current_syspath = set(sys.path) current_syspath = set(sys.path)
global _request_server_url
_request_server_url = request_server_url
sys.path.extend(path for path in product_test_list sys.path.extend(path for path in product_test_list
if path not in current_syspath) if path not in current_syspath)
......
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