From: Michael Tremer Date: Wed, 12 Oct 2022 14:27:02 +0000 (+0000) Subject: tests: Add tests for distros X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f9a38dd26b1cf9d79d75070512440d6154468c44;p=pbs.git tests: Add tests for distros Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 732c1644..ef46339b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -485,7 +485,8 @@ TESTS_ENVIRONMENT = \ abs_top_srcdir="$(abs_top_srcdir)" dist_check_SCRIPTS = \ - tests/setup.py + tests/setup.py \ + tests/distro.py EXTRA_DIST += \ tests/test.py diff --git a/tests/distro.py b/tests/distro.py new file mode 100755 index 00000000..b98aeebd --- /dev/null +++ b/tests/distro.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 + +import unittest + +import test + +from buildservice import distribution + +class DistroTestCase(test.TestCase): + """ + Tests everything around the Distro object + """ + def test_create(self): + """ + Tests whether we can create a distribution + """ + with self.db.transaction(): + distro = self.backend.distros.create("Random Test Distribution 1", "test1") + + # Check that we got the correct type back + self.assertIsInstance(distro, distribution.Distribution) + + # Check if the values got set correct + self.assertEqual(distro.name, "Random Test Distribution 1") + self.assertEqual(distro.tag, "test1") + + def test_default(self): + """ + Tests whether we can access the default distribution + """ + self.assertIsInstance(self.distro, distribution.Distribution) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test.py b/tests/test.py index e57a8499..6436572d 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import configparser +import functools import os import socket import tempfile @@ -76,3 +77,16 @@ class TestCase(unittest.IsolatedAsyncioTestCase): # Initialize the backend self.backend = Backend(f.name) + + # Create handle to the database + self.db = self.backend.db + + # Some random objects that are created on-demand so that we won't have to + # start from scratch each time... + + @functools.cached_property + def distro(self): + """ + Creates a distribution + """ + return self.backend.distros.create("Test Distribution 1", "test1")