Commit 948d8b57 authored by Jérome Perrin's avatar Jérome Perrin

zope4py2: fix usage of _Z2HOST

_Z2HOST / _Z2PORT no longer exist in Zope4, something was added in
component/egg-patch/Zope/0001-OFS-XMLExportImport.patch in SlapOS
software release, but we never had a strong need to patch there, we
were doing this (I guess) so that Testing.ZopeTestCase.utils.startZServer
knows that a server is already running and refuse to start another one,
but now that Zope's startZServer no longer exist, a local variable is
just fine.
parent ed32d077
...@@ -6,11 +6,6 @@ from UserDict import IterableUserDict ...@@ -6,11 +6,6 @@ from UserDict import IterableUserDict
import Lifetime import Lifetime
import transaction import transaction
from Testing import ZopeTestCase from Testing import ZopeTestCase
try:
from Testing.makerequest import _Z2HOST # XXX only on Zope4
from Testing import makerequest as utils
except: # BBB Zope 2.12
from Testing.ZopeTestCase import utils
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from zLOG import LOG, ERROR from zLOG import LOG, ERROR
from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY from Products.CMFActivity.Activity.Queue import VALIDATION_ERROR_DELAY
...@@ -19,6 +14,7 @@ from Products.ERP5Type.tests.utils import \ ...@@ -19,6 +14,7 @@ from Products.ERP5Type.tests.utils import \
addUserToDeveloperRole, createZServer, DummyMailHostMixin, parseListeningAddress addUserToDeveloperRole, createZServer, DummyMailHostMixin, parseListeningAddress
from Products.CMFActivity.ActivityTool import getCurrentNode from Products.CMFActivity.ActivityTool import getCurrentNode
_server_addr = None # (host, port) of the http server if it was started, None otherwise
class DictPersistentWrapper(IterableUserDict, object): class DictPersistentWrapper(IterableUserDict, object):
...@@ -154,7 +150,8 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -154,7 +150,8 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
def startZServer(self, verbose=False): def startZServer(self, verbose=False):
"""Start HTTP ZServer in background""" """Start HTTP ZServer in background"""
if utils._Z2HOST is None: global _server_addr
if _server_addr is None:
from Products.ERP5Type.tests.runUnitTest import log_directory from Products.ERP5Type.tests.runUnitTest import log_directory
log = os.path.join(log_directory, "Z2.log") log = os.path.join(log_directory, "Z2.log")
message = "Running %s server at %s:%s\n" message = "Running %s server at %s:%s\n"
...@@ -196,7 +193,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -196,7 +193,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
logger.propagate = False logger.propagate = False
hs = createServer(app_wrapper(webdav_ports=webdav_ports), hs = createServer(app_wrapper(webdav_ports=webdav_ports),
logger, sockets=sockets) logger, sockets=sockets)
utils._Z2HOST, utils._Z2PORT = hs.addr _server_addr = hs.addr
t = Thread(target=hs.run) t = Thread(target=hs.run)
t.setDaemon(1) t.setDaemon(1)
t.start() t.start()
...@@ -208,7 +205,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -208,7 +205,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
except RuntimeError as e: except RuntimeError as e:
ZopeTestCase._print(str(e)) ZopeTestCase._print(str(e))
else: else:
utils._Z2HOST, utils._Z2PORT = hs.server_name, hs.server_port _server_addr = hs.server_name, hs.server_port
_print(hs) _print(hs)
try: try:
_print(createZServer(log, zserver_type='webdav')) _print(createZServer(log, zserver_type='webdav'))
...@@ -224,7 +221,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -224,7 +221,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
if ActivityTool.currentNode == ActivityTool._server_address: if ActivityTool.currentNode == ActivityTool._server_address:
ActivityTool.currentNode = None ActivityTool.currentNode = None
ActivityTool._server_address = None ActivityTool._server_address = None
return utils._Z2HOST, utils._Z2PORT return _server_addr
def _registerNode(self, distributing, processing): def _registerNode(self, distributing, processing):
"""Register node to process and/or distribute activities""" """Register node to process and/or distribute activities"""
...@@ -245,7 +242,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -245,7 +242,7 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
@classmethod @classmethod
def unregisterNode(cls): def unregisterNode(cls):
if utils._Z2HOST is not None: if _server_addr is not None:
self = cls('unregisterNode') self = cls('unregisterNode')
self.app = self._app() self.app = self._app()
self._registerNode(distributing=0, processing=0) self._registerNode(distributing=0, processing=0)
......
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