The check() logic is really a factor of the test_urls test, so let's store it there Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx> --- tests/osinfo.py | 22 +++------------------- tests/test_urls.py | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/tests/osinfo.py b/tests/osinfo.py index 454170d..7847a3b 100644 --- a/tests/osinfo.py +++ b/tests/osinfo.py @@ -1,12 +1,8 @@ # This work is licensed under the GNU GPLv2 or later. # See the COPYING file in the top-level directory. -from http.client import responses -import logging import re -import requests - def _cache_property(fn): """ @@ -155,7 +151,7 @@ class Image(): def _get_url(self): url = self._root.find('url') if url is not None: - return URL(url.text) + return url.text return None url = _cache_property(_get_url) @@ -168,7 +164,7 @@ class Media(): def _get_url(self): url = self._root.find('url') if url is not None: - return URL(url.text) + return url.text return None url = _cache_property(_get_url) @@ -188,23 +184,11 @@ class Tree(): def _get_url(self): url = self._root.find('url') if url is not None: - return URL(url.text) + return url.text return None url = _cache_property(_get_url) -class URL(): - def __init__(self, url): - self._url = url - - def check(self): - logging.info("url: %s", self._url) - response = requests.head(self._url, allow_redirects=True) - logging.info("response: %s; code: %d", - responses[response.status_code], response.status_code) - return response.ok - - class ISO(): def __init__(self, root): self._root = root diff --git a/tests/test_urls.py b/tests/test_urls.py index 0639fe9..ea8c6f4 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -1,15 +1,29 @@ # This work is licensed under the GNU GPLv2 or later. # See the COPYING file in the top-level directory. +import http +import logging + +import requests + from . import util +def _check_url(url): + logging.info("url: %s", url) + response = requests.head(url, allow_redirects=True) + logging.info("response: %s; code: %d", + http.client.responses[response.status_code], + response.status_code) + return response.ok + + @util.os_parametrize('osxml', filter_images=True) def test_images_url(osxml): broken = [] for image in osxml.images: if image.url: - if not image.url.check(): + if not _check_url(image.url): broken.append(image.url) assert broken == [] @@ -19,7 +33,7 @@ def test_medias_url(osxml): broken = [] for media in osxml.medias: if media.url: - if not media.url.check(): + if not _check_url(media.url): broken.append(media.url) assert broken == [] @@ -29,6 +43,6 @@ def test_trees_url(osxml): broken = [] for tree in osxml.trees: if tree.url: - if not tree.url.check(): + if not _check_url(tree.url): broken.append(tree.url) assert broken == [] -- 2.21.0 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo