Example #1
0
 def test_run(self):
     fixture = self.useFixture(MockCmdRunnerPopenFixture())
     proc = cmd_runner.run(['foo', 'bar', 'baz'])
     # Call wait or else MockCmdRunnerPopenFixture() raises an
     # AssertionError().
     proc.wait()
     self.assertEqual(0, proc.returncode)
     self.assertEqual(['foo bar baz'], fixture.mock.commands_executed)
Example #2
0
 def test_tuple_with_sudo(self):
     fixture = self.useFixture(MockCmdRunnerPopenFixture())
     self.useFixture(MockSomethingFixture(os, 'getuid', lambda: 1000))
     cmd_runner.run((
         'foo',
         'bar',
     ), as_root=True).wait()
     self.assertEqual(['%s foo bar' % sudo_args],
                      fixture.mock.commands_executed)
 def test_unpack_package(self):
     fixture = MockCmdRunnerPopenFixture(assert_child_finished=False)
     self.useFixture(fixture)
     package_file_name = "package-to-unpack"
     with PackageUnpacker() as package_unpacker:
         package_unpacker.unpack_package(package_file_name)
         package_dir = package_unpacker.get_path(package_file_name)
     self.assertEquals([
         "tar -C %s -xf -" % package_dir,
         "dpkg --fsys-tarfile %s" % package_file_name
     ], fixture.mock.commands_executed)
Example #4
0
 def test_verify_files(self):
     fixture = self.useFixture(MockCmdRunnerPopenFixture())
     self.useFixture(
         MockSomethingFixture(tempfile, 'NamedTemporaryFile',
                              self.FakeTempFile))
     hash_filename = "dummy-file.txt"
     signature_filename = hash_filename + ".asc"
     verify_file_integrity([signature_filename])
     self.assertEqual([
         'gpg --status-file=%s --verify %s' %
         (self.FakeTempFile.name, signature_filename),
         'sha1sum -c %s' % hash_filename
     ], fixture.mock.commands_executed)
Example #5
0
    def test_package_installation_refused(self):
        self.useFixture(
            MockSomethingFixture(sys, 'stdout', open('/dev/null', 'w')))
        # We need this since we are getting user input via raw_input
        # and we need a 'n' to mimic a refused package installation.
        self.useFixture(MockSomethingFixture(sys, 'stdin', StringIO('n')))
        self.useFixture(MockCmdRunnerPopenFixture(self.output_string))

        CommandNotFound = try_import('CommandNotFound.CommandNotFound')

        if CommandNotFound is None:
            self.assertRaises(UnableToFindPackageProvidingCommand,
                              install_package_providing, 'mkfs.vfat')
        else:
            self.assertRaises(SystemExit, install_package_providing,
                              'mkfs.vfat')
Example #6
0
    def test_package_installation_accepted(self):
        self.useFixture(
            MockSomethingFixture(sys, 'stdout', open('/dev/null', 'w')))
        # We need this since we are getting user input via raw_input
        # and we need a 'Y' to proceed with the operations.
        self.useFixture(MockSomethingFixture(sys, 'stdin', StringIO('Y')))
        fixture = self.useFixture(MockCmdRunnerPopenFixture(
            self.output_string))

        try:
            install_package_providing('mkfs.vfat')
        except UnableToFindPackageProvidingCommand as inst:
            self.assertEqual("CommandNotFound python module does not exist.",
                             inst.args[0])
        else:
            self.assertEqual([
                'apt-get -s install dosfstools',
                '%s apt-get --yes install dosfstools' % sudo_args
            ], fixture.mock.commands_executed)
Example #7
0
 def test_chrooted(self):
     fixture = self.useFixture(MockCmdRunnerPopenFixture())
     cmd_runner.run(['foo', 'bar'], chroot='chroot_dir').wait()
     self.assertEqual(
         ['%s %s chroot_dir foo bar' % (sudo_args, chroot_args)],
         fixture.mock.commands_executed)
Example #8
0
 def test_run_as_root_as_root(self):
     fixture = self.useFixture(MockCmdRunnerPopenFixture())
     self.useFixture(MockSomethingFixture(os, 'getuid', lambda: 0))
     cmd_runner.run(['foo', 'bar'], as_root=True).wait()
     self.assertEqual(['foo bar'], fixture.mock.commands_executed)