]> git.ipfire.org Git - pbs.git/commitdiff
tests: Add tests for distros
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 14:27:02 +0000 (14:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 Oct 2022 14:27:02 +0000 (14:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/distro.py [new file with mode: 0755]
tests/test.py

index 732c164474df1130c89604248314e66cb83f0a1f..ef46339bb4e9d48245e5bc834086e7e63be386e3 100644 (file)
@@ -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 (executable)
index 0000000..b98aeeb
--- /dev/null
@@ -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()
index e57a8499bcf074b1a866b90c0907a88901ffaa4f..6436572de8446ab06d1fa96332b9b52337bd50f4 100644 (file)
@@ -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")