[PATCH osinfo-db 06/15] tests: test_urls: Combine the test cases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



They are all essentially doing the same thing: checking URL liveliness.
So let's scoop up all the URLs we want to test, then invoke the function
once per shortid

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 tests/test_urls.py | 43 +++++++++++++++++++++----------------------
 tests/util.py      |  5 +++--
 2 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/tests/test_urls.py b/tests/test_urls.py
index ea8c6f4..631cfc0 100644
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -4,6 +4,7 @@
 import http
 import logging
 
+import pytest
 import requests
 
 from . import util
@@ -18,31 +19,29 @@ def _check_url(url):
     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 _check_url(image.url):
-                broken.append(image.url)
-    assert broken == []
+def _collect_os_urls():
+    """
+    Iterate the OS list and return a list of pairs (shortid, [url list)
+    """
+    ret = []
 
+    for osxml in util.DataFiles.oses():
+        urls = []
+        urls.extend([i.url for i in osxml.images if i.url])
+        urls.extend([m.url for m in osxml.medias if m.url])
+        urls.extend([t.url for t in osxml.trees if t.url])
+        if urls:
+            ret.append((osxml.shortid, urls))
 
-@util.os_parametrize('osxml', filter_trees=True)
-def test_medias_url(osxml):
-    broken = []
-    for media in osxml.medias:
-        if media.url:
-            if not _check_url(media.url):
-                broken.append(media.url)
-    assert broken == []
+    return ret
 
 
-@util.os_parametrize('osxml', filter_media=True)
-def test_trees_url(osxml):
+@pytest.mark.parametrize('testdata', _collect_os_urls(),
+        ids=lambda testdata: testdata[0])
+def test_urls(testdata):
+    urls = testdata[1]
     broken = []
-    for tree in osxml.trees:
-        if tree.url:
-            if not _check_url(tree.url):
-                broken.append(tree.url)
+    for url in urls:
+        if not _check_url(url):
+            broken.append(url)
     assert broken == []
diff --git a/tests/util.py b/tests/util.py
index ac90af9..bf04b74 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -111,8 +111,9 @@ def os_parametrize(argname, **kwargs):
     extra arguments to DataFiles.oses()
     """
     def ids_cb(osxml):
-        # pytest passes us a weird value when oses is empty, like for
-        # test_urls image testing at the time of this commit
+        # pytest passes us a weird value when oses is empty, which
+        # might happen depending on how agressively we filter. So
+        # we can't assume we are passed an Os instance
         return getattr(osxml, "shortid", str(osxml))
 
     oses = DataFiles.oses(**kwargs)
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux