def do_deletion(self, delete_function):
        # Pass a function that does the deletion

        to_delete = ["delete/not/protected", "dir/to/delete", "make/a/dir/to/delete", "hello/delete"]
        touched_new = ["touch/this"]
        too_new = ["hello/new", "new"]
        all_dirs = to_delete + too_new + touched_new + ListDeletable.config.DIRS_TO_AVOID + protected_list

        start_time = time.time()
        for next_dir in all_dirs:
            if next_dir not in too_new:
                self.tmpdir.write(os.path.join(next_dir, "test_file.root"), bytearray(os.urandom(1024)))

        print "Waiting for some time."

        time.sleep(5)
        cutoff_time = int(time.time())
        time.sleep(5)

        for next_dir in too_new:
            self.tmpdir.write(os.path.join(next_dir, "test_file.root"), bytearray(os.urandom(1024)))
        for next_dir in touched_new:
            os.utime(self.tmpdir.getpath(os.path.join(next_dir, "test_file.root")), None)

        ListDeletable.config.MIN_AGE = int(time.time() - cutoff_time)
        ListDeletable.NOW = int(time.time())
        ListDeletable.main()

        delete_function()  # Function that does deletion is done here

        for dir in all_dirs:
            check_file = self.tmpdir.getpath(os.path.join(dir, "test_file.root"))
            self.assertEqual(
                os.path.exists(check_file), dir not in to_delete, "File status is unexpected: %s" % check_file
            )
Пример #2
0
    def do_deletion(self, delete_function):
        # Pass a function that does the deletion

        to_delete = [
            'delete/not/protected', 'dir/to/delete', 'make/a/dir/to/delete',
            'hello/delete'
        ]
        touched_new = ['touch/this']
        too_new = ['hello/new', 'new']
        all_dirs = to_delete + too_new + touched_new + \
            ListDeletable.config.DIRS_TO_AVOID + protected_list

        start_time = time.time()
        for next_dir in all_dirs:
            if next_dir not in too_new:
                self.tmpdir.write(os.path.join(next_dir, 'test_file.root'),
                                  bytearray(os.urandom(1024)))

        print 'Waiting for some time.'

        time.sleep(5)
        cutoff_time = int(time.time())
        time.sleep(5)

        for next_dir in too_new:
            self.tmpdir.write(os.path.join(next_dir, 'test_file.root'),
                              bytearray(os.urandom(1024)))
        for next_dir in touched_new:
            os.utime(
                self.tmpdir.getpath(os.path.join(next_dir, 'test_file.root')),
                None)

        ListDeletable.config.MIN_AGE = int(time.time() - cutoff_time)
        ListDeletable.NOW = int(time.time())
        ListDeletable.main()

        delete_function()  # Function that does deletion is done here

        for dir in all_dirs:
            check_file = self.tmpdir.getpath(
                os.path.join(dir, 'test_file.root'))
            self.assertEqual(os.path.exists(check_file), dir not in to_delete,
                             'File status is unexpected: %s' % check_file)
    def test_directory_reduction(self):
        test_to_delete = 'dir/to/delete/test_file.root'

        self.tmpdir.write(test_to_delete,
                          bytearray(os.urandom(1024)))

        print 'Waiting for some time.'

        time.sleep(5)
        cutoff_time = int(time.time())
        time.sleep(5)

        ListDeletable.config.WHICH_LIST = 'directories'
        ListDeletable.config.MIN_AGE = int(time.time() - cutoff_time)
        ListDeletable.NOW = int(time.time())
        ListDeletable.main()

        ListDeletable.do_delete()

        self.assertFalse(os.path.exists(self.tmpdir.getpath(test_to_delete)))
        self.assertFalse(os.path.exists(self.tmpdir.getpath(os.path.dirname(test_to_delete))))
        self.assertTrue(os.path.exists(self.tmpdir.getpath('dir')))
    def test_directory_reduction(self):
        test_to_delete = 'dir/to/delete/test_file.root'

        self.tmpdir.write(test_to_delete,
                          bytearray(os.urandom(1024)))

        print 'Waiting for some time.'

        time.sleep(5)
        cutoff_time = int(time.time())
        time.sleep(5)

        ListDeletable.config.WHICH_LIST = 'directories'
        ListDeletable.config.MIN_AGE = int(time.time() - cutoff_time)
        ListDeletable.NOW = int(time.time())
        ListDeletable.main()

        ListDeletable.do_delete()

        self.assertFalse(os.path.exists(self.tmpdir.getpath(test_to_delete)))
        self.assertFalse(os.path.exists(self.tmpdir.getpath(os.path.dirname(test_to_delete))))
        self.assertTrue(os.path.exists(self.tmpdir.getpath('dir')))