--- /dev/null
+#!/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()
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):
"""
# 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