From a30afe6e5ce34f7782293c838b6737e38619f8e3 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 3 Apr 2019 16:34:33 -0700 Subject: [PATCH] tests: Skip docs if not installed And make buildstamp test ignore the version number, since it might be devel or it might be an actual version when running against the installed package. Related: rhbz#1678937 --- tests/pylorax/test_buildstamp.py | 4 ++-- tests/pylorax/test_server.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/pylorax/test_buildstamp.py b/tests/pylorax/test_buildstamp.py index 73959ad1..55abb7c9 100644 --- a/tests/pylorax/test_buildstamp.py +++ b/tests/pylorax/test_buildstamp.py @@ -21,5 +21,5 @@ class BuildStampTestCase(unittest.TestCase): with patch.object(buildstamp, 'open', return_value=out_file): self.bstamp.write('/tmp/stamp.ini') self.assertIn("[Main]\nProduct=Lorax Tests\nVersion=0.1\nBugURL=https://github.com/rhinstaller/lorax/issues\nIsFinal=True\n", out_file.getvalue()) - # Skip UUID which is between IsFinal and Variant - self.assertIn("Variant=Server\n[Compose]\nLorax=devel", out_file.getvalue()) + # Skip UUID which is between IsFinal and Variant, and specific version which will change + self.assertIn("Variant=Server\n[Compose]\nLorax=", out_file.getvalue()) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index cd7f9869..bc6bbb56 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -72,6 +72,18 @@ def get_system_repo(): # Failed to find one, fall back to using base return "base" + +def docs_path(): + """Helper that points to where documentation should be. + + They may not be installed, so in that case the doc test should be skipped + """ + try: + return os.path.abspath(joinpaths(os.path.dirname(__file__), "../../../docs/html")) + except IndexError: + return "/usr/share/doc/lorax/html" + + class ServerTestCase(unittest.TestCase): @classmethod def setUpClass(self): @@ -804,11 +816,13 @@ class ServerTestCase(unittest.TestCase): self.assertRegex(response.data.decode("utf-8"), r"Lorax [\d.]+ documentation") self.assertRegex(response.data.decode("utf-8"), r"Copyright \d+, Red Hat, Inc.") + @unittest.skipUnless(os.path.exists(docs_path()), "Test requires a running API server") def test_api_docs(self): """Test the /api/docs/""" resp = self.server.get("/api/docs/") self.assert_documentation(resp) + @unittest.skipUnless(os.path.exists(docs_path()), "Test requires a running API server") def test_api_docs_with_existing_path(self): """Test the /api/docs/modules.html""" resp = self.server.get("/api/docs/modules.html")