Exemplo n.º 1
0
 def setUp(self):
     mox.MoxTestBase.setUp(self)
     self.chroot = Chroot()
     self.chroot.setup()
     self.chroot.install_debfile(
         os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
     self.addCleanup(self.chroot.remove)
     self.backend = aptBackend.PackageKitAptBackend([])
Exemplo n.º 2
0
class GetUpdatesTests(mox.MoxTestBase):
    """Test cases for detecting available updates."""
    def setUp(self):
        mox.MoxTestBase.setUp(self)
        self.chroot = Chroot()
        self.chroot.setup()
        self.chroot.install_debfile(
            os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
        self.addCleanup(self.chroot.remove)
        self.backend = aptBackend.PackageKitAptBackend([])

    def _catch_callbacks(self, *args):
        methods = list(args)
        methods.extend(("error", "finished"))
        for meth in methods:
            self.mox.StubOutWithMock(self.backend, meth)

    def test_get_updates(self):
        """Test checking for updates."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;", enums.INFO_NORMAL,
                             mox.IsA(str))
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])

    def test_get_security_updates(self):
        """Test checking for security updates."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;Debian-Security",
                             enums.INFO_SECURITY, "working package")
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_repository(
            os.path.join(get_tests_dir(), "repo/security"))
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])

    def test_get_backports(self):
        """Test checking for backports."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;",
                             enums.INFO_ENHANCEMENT, "working package")
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_repository(
            os.path.join(get_tests_dir(), "repo/backports"))
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])
Exemplo n.º 3
0
 def setUp(self):
     mox.MoxTestBase.setUp(self)
     self.chroot = Chroot()
     self.chroot.setup()
     self.chroot.install_debfile(os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
     self.addCleanup(self.chroot.remove)
     self.backend = aptBackend.PackageKitAptBackend([])
Exemplo n.º 4
0
class GetUpdatesTests(mox.MoxTestBase):

    """Test cases for detecting available updates."""

    def setUp(self):
        mox.MoxTestBase.setUp(self)
        self.chroot = Chroot()
        self.chroot.setup()
        self.chroot.install_debfile(os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
        self.addCleanup(self.chroot.remove)
        self.backend = aptBackend.PackageKitAptBackend([])

    def _catch_callbacks(self, *args):
        methods = list(args)
        methods.extend(("error", "finished"))
        for meth in methods:
            self.mox.StubOutWithMock(self.backend, meth)

    def test_get_updates(self):
        """Test checking for updates."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;", enums.INFO_NORMAL, mox.IsA(str))
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])

    def test_get_security_updates(self):
        """Test checking for security updates."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;Debian-Security", enums.INFO_SECURITY, "working package")
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_repository(os.path.join(get_tests_dir(), "repo/security"))
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])

    def test_get_backports(self):
        """Test checking for backports."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;", enums.INFO_ENHANCEMENT, "working package")
        self.backend.finished()
        self.mox.ReplayAll()
        self.chroot.add_repository(os.path.join(get_tests_dir(), "repo/backports"))
        self.backend._open_cache()
        self.backend.dispatch_command("get-updates", ["None"])
Exemplo n.º 5
0
 def setUp(self):
     mox.MoxTestBase.setUp(self)
     self.chroot = Chroot()
     self.chroot.setup()
     self.addCleanup(self.chroot.remove)
     self.backend = aptBackend.PackageKitAptBackend([])
Exemplo n.º 6
0
class CacheModifiersTests(mox.MoxTestBase):
    """Test cases for cache modifying methods of the APT backend.

    Note: In the test environment we emit the finished signal in the
          case of errors, too.
    """
    def setUp(self):
        mox.MoxTestBase.setUp(self)
        self.chroot = Chroot()
        self.chroot.setup()
        self.addCleanup(self.chroot.remove)
        self.backend = aptBackend.PackageKitAptBackend([])

    def _catch_callbacks(self, *args):
        methods = list(args)
        methods.extend(("error", "finished"))
        for meth in methods:
            self.mox.StubOutWithMock(self.backend, meth)

    def test_refresh_cache(self):
        """Test updating the cache using a local repository."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_trusted_key()
        path = os.path.join(self.chroot.path,
                            "etc/apt/sources.list.d/test.list")
        with open(path, "w") as part_file:
            part_file.write("deb file://%s ./" % REPO_PATH)
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("refresh-cache", ["true"])

        self.backend._open_cache()
        pkg = self.backend._cache["silly-base"]
        self.assertTrue(pkg.candidate.origins[0].trusted)

    def test_update_system(self):
        """Test upgrading the system."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.chroot.install_debfile(
            os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("update-system", ["true"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].installed.version,
                         "0.1-0update1")

    def test_update_packages(self):
        """Test upgrading the system."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.chroot.install_debfile(
            os.path.join(REPO_PATH, "silly-base_0.1-0_all.deb"))
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("update-packages",
                                      ["true", "silly-base;0.1-0update1;all;"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].installed.version,
                         "0.1-0update1")

    def test_install(self):
        """Test installation of a package from a repository."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-base;0.1-0update1;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)

    def test_install_fail(self):
        """Test handling the installation of failing packages."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_PACKAGE_FAILED_TO_INSTALL, mox.IsA(str),
                           True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-fail;0.1-0;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_install_timeout(self):
        """Test installation of hanging package."""
        if os.getuid() != 0:
            self.skipTest("The test requires root privileges")
        self._catch_callbacks()
        self.backend.error(enums.ERROR_PACKAGE_FAILED_TO_CONFIGURE,
                           mox.IsA(u""), True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        # Copy the files for a small execution environment to execute dash
        os.system("dpkg -L dash libc6 |"
                  "xargs -i cp --parents '{}' %s" % self.chroot.path)
        self.backend._open_cache()
        aptBackend.TIMEOUT_IDLE_INSTALLATION = 5
        # Install the package
        self.backend.dispatch_command(
            "install-packages", ["True", "silly-postinst-input;0.1-0;all;"])

    def test_install_only_trusted(self):
        """Test if the installation of a not trusted package fails."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_MISSING_GPG_SIGNATURE, mox.IsA(str),
                           True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository(copy_sig=False)
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["true", "silly-base;0.1-0update1;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_simulate_install(self):
        """Test simulation of package installation."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;",
                             enums.INFO_INSTALLING, "working package")
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Run the command
        self.backend.dispatch_command("simulate-install-packages",
                                      ["silly-depend-base;0.1-0;all;"])

    def test_remove_essential(self):
        """Test if we forbid to remove essential packages."""
        self.chroot.install_debfile(
            os.path.join(REPO_PATH, "silly-essential_0.1-0_all.deb"))
        self.backend._open_cache()

        self._catch_callbacks()
        self.backend.error(enums.ERROR_CANNOT_REMOVE_SYSTEM_PACKAGE,
                           mox.IsA(str), True)
        self.backend.finished()

        self.mox.ReplayAll()
        # Run the command
        self.backend.dispatch_command(
            "remove-packages", ["true", "true", "silly-essential;0.1-0;all;"])
        self.backend._open_cache()
        self.assertTrue(self.backend._cache["silly-essential"].is_installed)

    def test_remove_disallow_deps(self):
        """Test the removal of packages."""
        for pkg in [
                "silly-base_0.1-0_all.deb", "silly-depend-base_0.1-0_all.deb"
        ]:
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg))
        self.backend._open_cache()

        self._catch_callbacks()
        self.backend.error(enums.ERROR_DEP_RESOLUTION_FAILED, mox.IsA(str),
                           True)
        self.backend.finished()

        self.mox.ReplayAll()
        # Run the command
        self.backend.dispatch_command(
            "remove-packages", ["false", "true", "silly-base;0.1-0;all;"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed,
                         True)

    def test_remove(self):
        """Test the removal of packages."""
        self.backend._open_cache()
        for pkg in [
                "silly-base_0.1-0_all.deb", "silly-depend-base_0.1-0_all.deb"
        ]:
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg))
        ext_states = apt_pkg.config.find_file("Dir::State::extended_states")
        with open(ext_states, "w") as ext_states_file:
            ext_states_file.write("""Package: silly-base
Architecture: all
Auto-Installed: 1""")
        self.backend._open_cache()
        self._catch_callbacks()
        self.backend.finished()
        self.mox.ReplayAll()

        # Run the command
        self.backend.dispatch_command(
            "remove-packages",
            ["true", "true", "silly-depend-base;0.1-0;all;"])

        self.backend._open_cache()
        self.assertRaises(KeyError,
                          lambda: self.backend._cache["silly-depend-base"])
        self.assertRaises(KeyError, lambda: self.backend._cache["silly-base"])

    def test_install_file(self):
        """Test the installation of a local package file."""
        self.chroot.add_test_repository()
        debfile = os.path.join(REPO_PATH, "silly-depend-base_0.1-0_all.deb")
        debfile2 = os.path.join(REPO_PATH, "silly-essential_0.1-0_all.deb")
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package files
        self.backend.dispatch_command("install-files",
                                      ["true", "|".join((debfile, debfile2))])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-essential"].is_installed,
                         True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed,
                         True)

    def test_media_change_fail(self):
        """Test correct failure in the case of missing medium."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_MEDIA_CHANGE_REQUIRED, mox.IsA(unicode),
                           True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_trusted_key()
        self.chroot.add_cdrom_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-base;0.1-0;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_repair_system(self):
        """Test the recovery of broken dependencies."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        for pkg in ("silly-depend-base_0.1-0_all.deb",
                    "silly-broken_0.1-0_all.deb"):
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True)
        self.backend._cache.open()
        # Install the package
        self.backend.dispatch_command("repair-system", [True])
        self.backend._cache.open()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed,
                         True)
        self.assertEqual(self.backend._cache["silly-broken"].is_installed,
                         False)

    def test_simulate_repair_system(self):
        """Test simulation a system recovery."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;",
                             enums.INFO_INSTALLING, mox.IsA(str))
        self.backend.package("silly-broken;0.1-0;all;", enums.INFO_REMOVING,
                             mox.IsA(str))
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        for pkg in ("silly-depend-base_0.1-0_all.deb",
                    "silly-broken_0.1-0_all.deb"):
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True)
        self.backend._cache.open()
        # Install the package
        self.backend.dispatch_command("simulate-repair-system", [])
import os.path
import unittest
import tempfile
import shutil
import sys

import apt_pkg
import mox

from core import get_tests_dir, Chroot
from packagekit import enums
import aptBackend

REPO_PATH = os.path.join(get_tests_dir(), "repo")

chroot = Chroot()


class QueryTests(mox.MoxTestBase):
    """Test cases for non-destructive methods."""
    def setUp(self):
        mox.MoxTestBase.setUp(self)
        self.backend = aptBackend.PackageKitAptBackend([])

        self.workdir = tempfile.mkdtemp()
        self.orig_sys_path = sys.path

    def tearDown(self):
        shutil.rmtree(self.workdir)
        sys.path = self.orig_sys_path
Exemplo n.º 8
0
 def setUp(self):
     mox.MoxTestBase.setUp(self)
     self.chroot = Chroot()
     self.chroot.setup()
     self.addCleanup(self.chroot.remove)
     self.backend = aptBackend.PackageKitAptBackend([])
Exemplo n.º 9
0
class CacheModifiersTests(mox.MoxTestBase):

    """Test cases for cache modifying methods of the APT backend.

    Note: In the test environment we emit the finished signal in the
          case of errors, too.
    """

    def setUp(self):
        mox.MoxTestBase.setUp(self)
        self.chroot = Chroot()
        self.chroot.setup()
        self.addCleanup(self.chroot.remove)
        self.backend = aptBackend.PackageKitAptBackend([])

    def _catch_callbacks(self, *args):
        methods = list(args)
        methods.extend(("error", "finished"))
        for meth in methods:
            self.mox.StubOutWithMock(self.backend, meth)

    def test_refresh_cache(self):
        """Test updating the cache using a local repository."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_trusted_key()
        path = os.path.join(self.chroot.path,
                            "etc/apt/sources.list.d/test.list")
        with open(path, "w") as part_file:
            part_file.write("deb file://%s ./" % REPO_PATH)
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("refresh-cache", ["true"])

        self.backend._open_cache()
        pkg = self.backend._cache["silly-base"]
        self.assertTrue(pkg.candidate.origins[0].trusted)

    def test_update_system(self):
        """Test upgrading the system."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.chroot.install_debfile(os.path.join(REPO_PATH,
                                                 "silly-base_0.1-0_all.deb"))
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("update-system", ["true"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].installed.version,
                         "0.1-0update1")

    def test_update_packages(self):
        """Test upgrading the system."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.chroot.install_debfile(os.path.join(REPO_PATH,
                                                 "silly-base_0.1-0_all.deb"))
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("update-packages",
                                      ["true", "silly-base;0.1-0update1;all;"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].installed.version,
                         "0.1-0update1")

    def test_install(self):
        """Test installation of a package from a repository."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-base;0.1-0update1;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)

    def test_install_fail(self):
        """Test handling the installation of failing packages."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_PACKAGE_FAILED_TO_INSTALL,
                           mox.IsA(str), True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-fail;0.1-0;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_install_timeout(self):
        """Test installation of hanging package."""
        if os.getuid() != 0:
            self.skipTest("The test requires root privileges")
        self._catch_callbacks()
        self.backend.error(enums.ERROR_PACKAGE_FAILED_TO_CONFIGURE,
                           mox.IsA(u""), True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        # Copy the files for a small execution environment to execute dash
        os.system("dpkg -L dash libc6 |"
                  "xargs -i cp --parents '{}' %s" % self.chroot.path)
        self.backend._open_cache()
        aptBackend.TIMEOUT_IDLE_INSTALLATION = 5
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True",
                                       "silly-postinst-input;0.1-0;all;"])

    def test_install_only_trusted(self):
        """Test if the installation of a not trusted package fails."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_MISSING_GPG_SIGNATURE,
                           mox.IsA(str), True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository(copy_sig=False)
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["true", "silly-base;0.1-0update1;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_simulate_install(self):
        """Test simulation of package installation."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;",
                             enums.INFO_INSTALLING,
                             "working package")
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Run the command
        self.backend.dispatch_command("simulate-install-packages",
                                      ["silly-depend-base;0.1-0;all;"])

    def test_remove_essential(self):
        """Test if we forbid to remove essential packages."""
        self.chroot.install_debfile(os.path.join(REPO_PATH,
                                               "silly-essential_0.1-0_all.deb"))
        self.backend._open_cache()

        self._catch_callbacks()
        self.backend.error(enums.ERROR_CANNOT_REMOVE_SYSTEM_PACKAGE,
                           mox.IsA(str), True)
        self.backend.finished()

        self.mox.ReplayAll()
        # Run the command
        self.backend.dispatch_command("remove-packages",
                                      ["true", "true",
                                       "silly-essential;0.1-0;all;"])
        self.backend._open_cache()
        self.assertTrue(self.backend._cache["silly-essential"].is_installed)

    def test_remove_disallow_deps(self):
        """Test the removal of packages."""
        for pkg in ["silly-base_0.1-0_all.deb",
                    "silly-depend-base_0.1-0_all.deb"]:
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg))
        self.backend._open_cache()

        self._catch_callbacks()
        self.backend.error(enums.ERROR_DEP_RESOLUTION_FAILED,
                           mox.IsA(str), True)
        self.backend.finished()

        self.mox.ReplayAll()
        # Run the command
        self.backend.dispatch_command("remove-packages",
                                      ["false", "true",
                                       "silly-base;0.1-0;all;"])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed,
                         True)

    def test_remove(self):
        """Test the removal of packages."""
        self.backend._open_cache()
        for pkg in ["silly-base_0.1-0_all.deb",
                    "silly-depend-base_0.1-0_all.deb"]:
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg))
        ext_states = apt_pkg.config.find_file("Dir::State::extended_states")
        with open(ext_states, "w") as ext_states_file:
            ext_states_file.write("""Package: silly-base
Architecture: all
Auto-Installed: 1""")
        self.backend._open_cache()
        self._catch_callbacks()
        self.backend.finished()
        self.mox.ReplayAll()

        # Run the command
        self.backend.dispatch_command("remove-packages",
                                      ["true", "true",
                                       "silly-depend-base;0.1-0;all;"])

        self.backend._open_cache()
        self.assertRaises(KeyError,
                          lambda: self.backend._cache["silly-depend-base"])
        self.assertRaises(KeyError, lambda: self.backend._cache["silly-base"])

    def test_install_file(self):
        """Test the installation of a local package file."""
        self.chroot.add_test_repository()
        debfile = os.path.join(REPO_PATH, "silly-depend-base_0.1-0_all.deb")
        debfile2 = os.path.join(REPO_PATH, "silly-essential_0.1-0_all.deb")
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        self.backend._open_cache()
        # Install the package files
        self.backend.dispatch_command("install-files",
                                      ["true", "|".join((debfile, debfile2))])

        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-essential"].is_installed,
                         True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed,
                         True)

    def test_media_change_fail(self):
        """Test correct failure in the case of missing medium."""
        self._catch_callbacks()
        self.backend.error(enums.ERROR_MEDIA_CHANGE_REQUIRED, mox.IsA(unicode),
                           True)
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_trusted_key()
        self.chroot.add_cdrom_repository()
        self.backend._open_cache()
        # Install the package
        self.backend.dispatch_command("install-packages",
                                      ["True", "silly-base;0.1-0;all;"])
        self.backend._open_cache()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, False)

    def test_repair_system(self):
        """Test the recovery of broken dependencies."""
        self._catch_callbacks()
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        for pkg in ("silly-depend-base_0.1-0_all.deb", "silly-broken_0.1-0_all.deb"):
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True)
        self.backend._cache.open()
        # Install the package
        self.backend.dispatch_command("repair-system", [True])
        self.backend._cache.open()
        self.assertEqual(self.backend._cache["silly-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-depend-base"].is_installed, True)
        self.assertEqual(self.backend._cache["silly-broken"].is_installed, False)

    def test_simulate_repair_system(self):
        """Test simulation a system recovery."""
        self._catch_callbacks("package")
        self.backend.package("silly-base;0.1-0update1;all;",
                             enums.INFO_INSTALLING, mox.IsA(str))
        self.backend.package("silly-broken;0.1-0;all;", enums.INFO_REMOVING, mox.IsA(str))
        self.backend.finished()
        # Setup environment
        self.mox.ReplayAll()
        self.chroot.add_test_repository()
        for pkg in ("silly-depend-base_0.1-0_all.deb", "silly-broken_0.1-0_all.deb"):
            self.chroot.install_debfile(os.path.join(REPO_PATH, pkg), True)
        self.backend._cache.open()
        # Install the package
        self.backend.dispatch_command("simulate-repair-system", [])