[FIX] tests: fix chrome headless to work with any local HOST

Before this commit, changing the value of the HOST variable didn't work because
it wasn't correctly used everywhere.

Moreover, the `web.base.url` was not correctly set: it is set during
authenticate, but when calling it from the console instead of from a request,
which is the case for tests, it is not able to grab and set the URL as needed.

PR: #30000
This commit is contained in:
Sébastien Theys
2019-01-17 08:16:11 +00:00
committed by Jeremy Kersten
parent 5f6a491265
commit 9df7d244a0
+7 -3
View File
@@ -530,6 +530,7 @@ class ChromeBrowser():
'--user-data-dir': self.user_data_dir,
'--disable-translate': '',
'--window-size': '1366x768',
'--remote-debugging-address': HOST,
'--remote-debugging-port': str(self.devtools_port),
'--no-sandbox': '',
}
@@ -572,7 +573,7 @@ class ChromeBrowser():
command = os.path.join('json', command).strip('/')
while timeout > 0:
try:
url = werkzeug.urls.url_join('http://127.0.0.1:%s/' % self.devtools_port, command)
url = werkzeug.urls.url_join('http://%s:%s/' % (HOST, self.devtools_port), command)
self._logger.info('Url : %s', url)
r = requests.get(url, timeout=3)
if r.ok:
@@ -881,7 +882,7 @@ class HttpCase(TransactionCase):
odoo.http.root.session_store.save(session)
if self.browser:
self._logger.info('Setting session cookie in browser')
self.browser.set_cookie('session_id', self.session_id, '/', '127.0.0.1')
self.browser.set_cookie('session_id', self.session_id, '/', HOST)
def browser_js(self, url_path, code, ready='', login=None, timeout=60, **kw):
""" Test js code running in the browser
@@ -905,7 +906,10 @@ class HttpCase(TransactionCase):
try:
self.authenticate(login, login)
url = "http://%s:%s%s" % (HOST, PORT, url_path or '/')
base_url = "http://%s:%s" % (HOST, PORT)
ICP = self.env['ir.config_parameter']
ICP.set_param('web.base.url', base_url)
url = "%s%s" % (base_url, url_path or '/')
self._logger.info('Open "%s" in browser', url)
if odoo.tools.config['logfile']: