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

testXHTML: retry connections to validator.erp5.net

Sometimes validator.erp5.net replies with error code 502 and this cause
ERP5 tests to fail. While this is a bit like ignoring problems, problems
with validator.erp5.net should not impact ERP5 tests results.

/reviewed-on !968
parent be2399e8
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
import unittest import unittest
import os import os
import requests import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -516,11 +518,23 @@ class TestXHTML(TestXHTMLMixin): ...@@ -516,11 +518,23 @@ class TestXHTML(TestXHTMLMixin):
class NuValidator(object): class NuValidator(object):
def __init__(self, show_warnings): def __init__(self, show_warnings, validator_url='https://validator.erp5.net/'):
self.show_warnings = show_warnings self.show_warnings = show_warnings
self.name = 'nu' self.name = 'nu'
self.validator_url = validator_url
def _parse_validation_results(self, validator_url, response): self.validator_session = requests.Session()
# retries HTTP 502 errors which sometimes happen with validator.erp5.net
self.validator_session.mount(
self.validator_url,
requests.adapters.HTTPAdapter(
max_retries=Retry(
total=3,
read=3,
connect=3,
backoff_factor=.5,
status_forcelist=(502, ))))
def _parse_validation_results(self, response):
""" """
parses the validation results, returns a list of tuples: parses the validation results, returns a list of tuples:
line_number, col_number, error description line_number, col_number, error description
...@@ -529,7 +543,7 @@ class NuValidator(object): ...@@ -529,7 +543,7 @@ class NuValidator(object):
return [ return [
[(None, None, [(None, None,
'Contacting the external validator %s failed with status: %i' % 'Contacting the external validator %s failed with status: %i' %
(validator_url, response.status_code))], (self.validator_url, response.status_code))],
[] []
] ]
...@@ -557,14 +571,13 @@ class NuValidator(object): ...@@ -557,14 +571,13 @@ class NuValidator(object):
''' '''
retrun two list : a list of errors and an other for warnings retrun two list : a list of errors and an other for warnings
''' '''
validator_url = 'https://validator.erp5.net/' response = self.validator_session.post(self.validator_url,
response = requests.post(validator_url,
data=page_source.encode('UTF-8'), data=page_source.encode('UTF-8'),
params={'out': 'json'}, params={'out': 'json'},
headers={ headers={
'Content-Type': 'text/html; charset=UTF-8' 'Content-Type': 'text/html; charset=UTF-8'
}) })
return self._parse_validation_results(validator_url, response) return self._parse_validation_results(response)
class TidyValidator(object): class TidyValidator(object):
......
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