Exemplo n.º 1
0
    def test_link(self):
        """Unit test for links with is_link() and get_recycle_bin()"""
        if not common.destructive_tests('windows link'):
            return

        # make a normal directory with a file in it
        real_dir = os.path.join(self.tempdir, 'real_dir')
        os.mkdir(real_dir)
        self.assertExists(real_dir)
        self.assertEqual(False, is_link(real_dir))

        canary_fn = os.path.join(real_dir, 'do_not_delete')
        common.touch_file(canary_fn)
        self.assertExists(canary_fn)
        self.assertEqual(False, is_link(canary_fn))

        # link to the normal directory
        link_dir = os.path.join(self.tempdir, 'link_dir')
        args = ('cmd', '/c', 'mklink', '/d', link_dir, real_dir)
        from bleachbit.General import run_external
        (rc, stdout, stderr) = run_external(args)
        self.assertEqual(rc, 0, stderr)
        self.assertExists(link_dir)
        self.assertEqual(True, is_link(link_dir))

        # put the link in the recycle bin
        move_to_recycle_bin(link_dir)

        # clear the recycle bin
        for f in get_recycle_bin():
            FileUtilities.delete(f, shred=False)

        # verify the canary is still there
        self.assertExists(canary_fn)
Exemplo n.º 2
0
    def test_link(self):
        """Unit test for links with is_link() and get_recycle_bin()"""
        if not common.destructive_tests('windows link'):
            return

        # make a normal directory with a file in it
        real_dir = os.path.join(self.tempdir, 'real_dir')
        os.mkdir(real_dir)
        self.assertExists(real_dir)
        self.assertEqual(False, is_link(real_dir))

        canary_fn = os.path.join(real_dir, 'do_not_delete')
        common.touch_file(canary_fn)
        self.assertExists(canary_fn)
        self.assertEqual(False, is_link(canary_fn))

        # link to the normal directory
        link_dir = os.path.join(self.tempdir, 'link_dir')
        args = ('cmd', '/c', 'mklink', '/d', link_dir, real_dir)
        from bleachbit.General import run_external
        (rc, stdout, stderr) = run_external(args)
        self.assertEqual(rc, 0, stderr)
        self.assertExists(link_dir)
        self.assertEqual(True, is_link(link_dir))

        # put the link in the recycle bin
        move_to_recycle_bin(link_dir)

        # clear the recycle bin
        for f in get_recycle_bin():
            FileUtilities.delete(f, shred=False)

        # verify the canary is still there
        self.assertExists(canary_fn)
Exemplo n.º 3
0
    def _test_link_helper(self, mklink_option, clear_recycle_bin):
        """Helper function for testing for links with is_link() and
        get_recycle_bin()

        It gets called four times for the combinations of the two
        parameters. It's called by four unit tests four accounting
        purposes. In other words, we don't want to count a test as
        skipped if part of it succeeded.

        mklink /j = directory junction
        directory junction does not require administrator privileges

        mklink /d=directory symbolic link
        requires administrator privileges
        """
        if mklink_option == '/d':
            self.skipUnlessAdmin()
        # make a normal directory with a file in it
        real_dir = os.path.join(self.tempdir, 'real_dir')
        os.mkdir(real_dir)
        self.assertExists(real_dir)
        self.assertEqual(False, is_link(real_dir))

        canary_fn = os.path.join(real_dir, 'do_not_delete')
        common.touch_file(canary_fn)
        self.assertExists(canary_fn)
        self.assertEqual(False, is_link(canary_fn))

        # link to the normal directory
        link_dir = os.path.join(self.tempdir, 'link_dir')
        args = ('cmd', '/c', 'mklink', mklink_option, link_dir, real_dir)
        from bleachbit.General import run_external
        (rc, stdout, stderr) = run_external(args)
        self.assertEqual(rc, 0, stderr)
        self.assertExists(link_dir)
        self.assertEqual(True, is_link(link_dir))

        if not clear_recycle_bin:
            os.rmdir(link_dir)
            self.assertNotExists(link_dir)
            shutil.rmtree(real_dir, True)
            if not common.destructive_tests('windows link'):
                self.skipTest('destructive tests are disabled')
            return

        # put the link in the recycle bin
        move_to_recycle_bin(link_dir)

        # clear the recycle bin
        for f in get_recycle_bin():
            FileUtilities.delete(f, shred=False)

        # verify the canary is still there
        self.assertExists(canary_fn)

        # clean up
        shutil.rmtree(real_dir, True)
Exemplo n.º 4
0
    def test_CleanerML(self):
        """Unit test for class CleanerML"""

        xmlcleaner = CleanerML("doc/example_cleaner.xml")

        self.assertIsInstance(xmlcleaner, CleanerML)
        self.assertIsInstance(xmlcleaner.cleaner, Cleaner.Cleaner)

        # preview
        self.run_all(xmlcleaner, False)

        # really delete if user allows
        if common.destructive_tests('example_cleaner.xml'):
            self.run_all(xmlcleaner, True)
Exemplo n.º 5
0
    def test_CleanerML(self):
        """Unit test for class CleanerML"""

        xmlcleaner = CleanerML("doc/example_cleaner.xml")

        self.assertIsInstance(xmlcleaner, CleanerML)
        self.assertIsInstance(xmlcleaner.cleaner, Cleaner.Cleaner)

        # preview
        self.run_all(xmlcleaner, False)

        # really delete if user allows
        if common.destructive_tests('example_cleaner.xml'):
            self.run_all(xmlcleaner, True)
Exemplo n.º 6
0
 def test_get_recycle_bin(self):
     """Unit test for get_recycle_bin"""
     for f in get_recycle_bin():
         self.assertExists(extended_path(f))
     if not common.destructive_tests('get_recycle_bin'):
         return
     put_files_into_recycle_bin()
     # clear recycle bin
     counter = 0
     for f in get_recycle_bin():
         counter += 1
         FileUtilities.delete(f)
     self.assertGreaterEqual(counter, 3, 'deleted %d' % counter)
     # now it should be empty
     for f in get_recycle_bin():
         self.fail('recycle bin should be empty, but it is not')
Exemplo n.º 7
0
 def test_get_recycle_bin(self):
     """Unit test for get_recycle_bin"""
     for f in get_recycle_bin():
         self.assertExists(extended_path(f))
     if not common.destructive_tests('get_recycle_bin'):
         return
     put_files_into_recycle_bin()
     # clear recycle bin
     counter = 0
     for f in get_recycle_bin():
         counter += 1
         FileUtilities.delete(f)
     self.assertGreaterEqual(counter, 3, 'deleted %d' % counter)
     # now it should be empty
     for f in get_recycle_bin():
         self.fail('recycle bin should be empty, but it is not')
Exemplo n.º 8
0
    def test_CleanerML(self):
        """Unit test for class CleanerML"""

        xmlcleaner = CleanerML("../doc/example_cleaner.xml")

        self.assertIsInstance(xmlcleaner, CleanerML)
        self.assertIsInstance(xmlcleaner.cleaner, Cleaner.Cleaner)

        def run_all(really_delete):
            for (option_id, __name) in xmlcleaner.cleaner.get_options():
                for cmd in xmlcleaner.cleaner.get_commands(option_id):
                    for result in cmd.execute(really_delete):
                        common.validate_result(self, result, really_delete)

        # preview
        run_all(False)

        # really delete if user allows
        if common.destructive_tests('example_cleaner.xml'):
            run_all(True)
Exemplo n.º 9
0
 def test_empty_recycle_bin(self):
     """Unit test for empty_recycle_bin"""
     # check the function basically works
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=False)
         self.assertIsInteger(ret)
     if not common.destructive_tests('recycle bin'):
         return
     # check it deletes files for fixed drives
     put_files_into_recycle_bin()
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=True)
         self.assertIsInteger(ret)
     # check it deletes files for all drives
     put_files_into_recycle_bin()
     ret = empty_recycle_bin(None, really_delete=True)
     self.assertIsInteger(ret)
     # Repeat two for reasons.
     # 1. Trying to empty an empty recycling bin can cause
     #    a 'catastrophic failure' error (handled in the function)
     # 2. It should show zero bytes were deleted
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=True)
         self.assertEqual(ret, 0)
Exemplo n.º 10
0
 def test_empty_recycle_bin(self):
     """Unit test for empty_recycle_bin"""
     # check the function basically works
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=False)
         self.assertIsInstance(ret, (int, long))
     if not common.destructive_tests('recycle bin'):
         return
     # check it deletes files for fixed drives
     put_files_into_recycle_bin()
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=True)
         self.assertIsInstance(ret, (int, long))
     # check it deletes files for all drives
     put_files_into_recycle_bin()
     ret = empty_recycle_bin(None, really_delete=True)
     self.assertIsInstance(ret, (int, long))
     # Repeat two for reasons.
     # 1. Trying to empty an empty recycling bin can cause
     #    a 'catastrophic failure' error (handled in the function)
     # 2. It should show zero bytes were deleted
     for drive in get_fixed_drives():
         ret = empty_recycle_bin(drive, really_delete=True)
         self.assertEqual(ret, 0)