diff --git a/tests/modules/Jenkinsfile b/tests/modules/Jenkinsfile index 3ce4911d4..f9a3eb88a 100644 --- a/tests/modules/Jenkinsfile +++ b/tests/modules/Jenkinsfile @@ -6,7 +6,7 @@ def prepareDocker () { def uid = sh returnStdout: true, script: 'id -u' writeFile file: 'Dockerfile', text: """ FROM python:3.8-buster - RUN pip install pytest-cov && \\ + RUN pip install pytest-cov PySocks && \\ useradd -m -u ${uid.trim()} jenkins """ img = docker.build('local:test-all-comics') @@ -22,7 +22,9 @@ def runTests() { sh "pip install --user -e .[css,dev]" } stage ('Run tests') { - sh "TESTALL=1 py.test -v --cov=dosagelib --cov-report xml --tb=short -n10 --junitxml=junit.xml tests/modules/check_comics.py || true" + withCredentials([string(credentialsId: 'proxymap', variable: 'PROXYMAP')]) { + sh "TESTALL=1 py.test -v --cov=dosagelib --cov-report xml --tb=short -n10 --junitxml=junit.xml tests/modules/check_comics.py || true" + } } stage('Report') { junit 'junit.xml' diff --git a/tests/modules/check_comics.py b/tests/modules/check_comics.py index a8363e66a..0e11a9d7a 100644 --- a/tests/modules/check_comics.py +++ b/tests/modules/check_comics.py @@ -2,8 +2,10 @@ # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam # Copyright (C) 2015-2020 Tobias Gruetzmacher -import re +import json import multiprocessing +import os +import re import warnings from urllib.parse import urlsplit @@ -40,6 +42,7 @@ def _test_comic(outdir, scraperobj): num_strips = 0 strip = None files = [] + PROXYMAP.apply(scraperobj.name) for strip in scraperobj.getStrips(MaxStrips): files.append(_check_strip(outdir, strip, scraperobj.multipleImagesPerStrip)) @@ -110,3 +113,25 @@ def _check_stripurl(strip, scraperobj): if not mo: warnings.warn('strip URL {!r} does not match stripUrl pattern {}'.format( strip.strip_url, urlmatch)) + + +class ProxyConfig: + """Loads proxy config from an environment variable and applies it for each test.""" + def __init__(self): + self.config = {} + if 'PROXYMAP' in os.environ: + for regex, server in json.loads(os.environ['PROXYMAP']).items(): + self.config[re.compile(regex)] = server + + def apply(self, name): + useserver = '' + for regex, server in self.config.items(): + if regex.match(name): + useserver = server + break + os.environ['http_proxy'] = useserver + os.environ['https_proxy'] = useserver + + +# External proxy config to fetch some modules via proxies +PROXYMAP = ProxyConfig()