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

index 5c7380cb6da4cb8c7ce527e7d260f16e40a236c6..724c69d298433f8f41c41917e9ee72dca257f3d4 100644 (file)
@@ -487,6 +487,7 @@ TESTS_ENVIRONMENT = \
 dist_check_SCRIPTS = \
        tests/setup.py \
        tests/distro.py \
+       tests/package.py \
        tests/repo.py \
        tests/upload.py
 
diff --git a/tests/package.py b/tests/package.py
new file mode 100755 (executable)
index 0000000..931e5ed
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/python3
+
+import datetime
+import os
+import pakfire
+import unittest
+
+import test
+
+from buildservice import packages
+
+class PackageTestCase(test.TestCase):
+       """
+               Tests everything around packages
+       """
+       async def test_create(self):
+               """
+                       Tests whether we can create/import a package
+               """
+               path = self.source_path("tests/data/beep-1.3-2.ip3.x86_64.pfm")
+
+               # Create the package
+               with self.db.transaction():
+                       package = await self._create_package(path)
+
+               # Check whether the package has been copied to the correct place
+               self.assertTrue(os.path.exists(package.path))
+               self.assertTrue(package.path.startswith(self.backend.path("packages")))
+
+               # Check metadata
+               self.assertEqual(package.name, "beep")
+               self.assertEqual(package.evr, "1.3-2.ip3")
+               self.assertEqual(package.arch, "x86_64")
+               self.assertEqual(package.groups, [])
+               self.assertEqual(package.maintainer, None)
+               self.assertEqual(package.license, "GPLv2+")
+               self.assertEqual(package.url, "http://www.johnath.com/beep/")
+               self.assertEqual(package.summary, "Beep the PC speaker any number of ways.")
+               self.assertEqual(package.description,
+                       """Beep allows the user to control the PC speaker with precision, allowing
+different sounds to indicate different events. While it can be run quite happily
+on the commandline, it's intended place of residence is within shell/perl
+scripts, notifying the user when something interesting occurs. Of course, it has
+no notion of what's interesting, but it's real good at that notifying part.""")
+               self.assertEqual(package.size, 17856)
+               self.assertEqual(package.uuid, "0d35b9fa-5254-4a16-ba5b-a171362ade5d")
+               # XXX BUILD ID MISSING
+               self.assertEqual(package.build_host, "cornelius.ipfire.org")
+               self.assertEqual(package.build_time, datetime.datetime(2016, 10, 21, 9, 46, 54))
+               self.assertEqual(package.filesize, 30720)
+
+       async def test_double_import(self):
+               path = self.source_path("tests/data/beep-1.3-2.ip3.x86_64.pfm")
+
+               # Import the same package twice
+               with self.db.transaction():
+                       package1 = await self._create_package(path)
+                       package2 = await self._create_package(path)
+
+               # The package should not have been imported again, and therefore have the same ID
+               self.assertEqual(package1.id, package2.id)
+
+       async def test_delete(self):
+               path = self.source_path("tests/data/beep-1.3-2.ip3.x86_64.pfm")
+
+               # Create the package
+               with self.db.transaction():
+                       package = await self._create_package(path)
+
+               # Delete the package
+               with self.db.transaction():
+                       package.delete()
+
+               # Check if the payload has been removed
+               # XXX currently, packages are not deleted
+               #self.assertFalse(os.path.exists(package.path))
+
+
+if __name__ == "__main__":
+       unittest.main()
index 07958b13b871c7bca45095e0a5646eb9ceb63c7e..ebab1b435ae4f663aed710ad8b5ca5720f866b0b 100644 (file)
@@ -7,9 +7,12 @@ import socket
 import tempfile
 import unittest
 
+from pakfire._pakfire import Archive
+
 from buildservice import Backend
 from buildservice import database
 from buildservice import misc
+from buildservice import packages
 
 class TestCase(unittest.IsolatedAsyncioTestCase):
        """
@@ -114,3 +117,24 @@ class TestCase(unittest.IsolatedAsyncioTestCase):
 
                # Create a repository
                self.repo = await self.backend.repos.create(self.distro, "Default Test Repository")
+
+       async def _create_package(self, path):
+               """
+                       Helper function to import a package from path
+               """
+               # Check if the file exists
+               self.assertTrue(os.path.exists(path))
+
+               # Open the archive
+               archive = await self.backend.open(path)
+
+               # Check if we received the correct type
+               self.assertIsInstance(archive, Archive)
+
+               # Create the package
+               package = await self.backend.packages.create(archive)
+
+               # Check if we received the correct type
+               self.assertIsInstance(package, packages.Package)
+
+               return package