From: Michael Tremer Date: Wed, 12 Oct 2022 16:17:57 +0000 (+0000) Subject: tests: Add tests for packages X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a5f100fd8fefc1bca61ab42fec9da60e68acd8b;p=pbs.git tests: Add tests for packages Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 5c7380cb..724c69d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 00000000..931e5edd --- /dev/null +++ b/tests/package.py @@ -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() diff --git a/tests/test.py b/tests/test.py index 07958b13..ebab1b43 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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