From: Michael Tremer Date: Wed, 19 Oct 2022 14:07:09 +0000 (+0000) Subject: tests: Allow faking the distribution X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=823d18bf07bd717eff1c3f3ae501ebfe78d873de;p=pbs.git tests: Allow faking the distribution Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index b83f5565..8bd46594 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -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 diff --git a/tests/test.py b/tests/test.py index c0817ba2..8a3a9976 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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)