]> git.ipfire.org Git - pbs.git/commitdiff
tests: Allow faking the distribution
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 14:07:09 +0000 (14:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 14:07:09 +0000 (14:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/packages.py
tests/test.py

index b83f5565f9c94cae6cc328f200f480a727539d88..8bd465949eb5037a8b04cb043a29c8a5eb332461 100644 (file)
@@ -74,10 +74,13 @@ class Packages(base.Object):
                        """, uuid,
                )
 
-       async def create(self, upload):
+       async def create(self, upload, distro=None):
                """
                        Creates a new package from an uploaded file
                """
+               if not self.backend.test and distro:
+                       raise RuntimeError("Cannot alter distro when not in test mode")
+
                # Check if the upload has been completed
                if not upload.is_completed():
                        raise RuntimeError("Cannot import package from incomplete upload")
@@ -96,11 +99,12 @@ class Packages(base.Object):
                log.debug("Importing package %s..." % package)
 
                # Find a matching distribution
-               distro = self.backend.distros.get_by_tag(package.distribution)
                if not distro:
-                       log.error("Could not find distribution '%s'" % package.distribution)
+                       distro = self.backend.distros.get_by_tag(package.distribution)
+                       if not distro:
+                               log.error("Could not find distribution '%s'" % package.distribution)
 
-                       raise NoSuchDistroError(package.distribution)
+                               raise NoSuchDistroError(package.distribution)
 
                pkg = self._get_package("""
                        INSERT INTO
index c0817ba20c961557c0aa667772efad14e267188a..8a3a99766cf7922b87714e82d64723b2ac66afc5 100644 (file)
@@ -148,7 +148,7 @@ class TestCase(unittest.IsolatedAsyncioTestCase):
                upload = await self._create_upload(path)
 
                # Create the package
-               package = await self.backend.packages.create(upload)
+               package = await self.backend.packages.create(upload, distro=self.distro)
 
                # Check if we received the correct type
                self.assertIsInstance(package, packages.Package)