Example #1
0
    def test_Chaff(self):
        """Unit test for class Chaff"""
        tmp_dir = mkdtemp(prefix='bleachbit-chaff')
        # con=Clinton content
        con_path = os.path.join(tmp_dir, 'content.json.bz2')
        # sub=Clinton subject
        sub_path = os.path.join(tmp_dir, 'subject.json.bz2')
        ts_path = os.path.join(tmp_dir, 'ts.json.bz2')  # ts = 2600 Magazine

        for i in ('download', 'already downloaded'):
            ret = download_models(content_model_path=con_path,
                                  subject_model_path=sub_path,
                                  twentysixhundred_model_path=ts_path)
            self.assertIsInstance(ret, bool)
            self.assertTrue(ret)

        self.assertExists(con_path)
        self.assertExists(sub_path)
        self.assertExists(ts_path)

        generated_file_names = generate_emails(5, tmp_dir, con_path, sub_path)

        self.assertEqual(len(generated_file_names), 5)

        for fn in generated_file_names:
            self.assertExists(fn)
            self.assertGreater(getsize(fn), 100)

        generated_file_names = generate_2600(5, tmp_dir, ts_path)

        rmtree(tmp_dir)
Example #2
0
    def test_touch_file(self):
        """Unit test for touch_file"""
        fn = os.path.join(self.tempdir, 'test_touch_file')
        self.assertNotExists(fn)

        # Create empty file.
        common.touch_file(fn)
        from bleachbit.FileUtilities import getsize
        self.assertExists(fn)
        self.assertEqual(0, getsize(fn))

        # Increase size of file.
        fsize = 2**13
        with open(fn, "w") as f:
            f.write(' '*fsize)
        self.assertEqual(fsize, getsize(fn))

        # Do not truncate.
        common.touch_file(fn)
        self.assertExists(fn)
        self.assertEqual(fsize, getsize(fn))
Example #3
0
    def get_commands(self):
        # Open the file with a non-exclusive lock, so the file should
        # be truncated and marked for deletion. This is checked just on
        # on Windows.
        f = os.open(self.pathname, os.O_RDWR)
        yield Command.Delete(self.pathname)
        assert(os.path.exists(self.pathname))
        from bleachbit.FileUtilities import getsize
        assert(0==getsize(self.pathname))
        os.close(f)

        # real file, should succeed
        yield Command.Delete(self.pathname)
Example #4
0
    def get_commands(self):
        # Open the file with a non-exclusive lock, so the file should
        # be truncated and marked for deletion. This is checked just on
        # on Windows.
        f = os.open(self.pathname, os.O_RDWR)
        # Without admin privileges, this delete fails.
        yield Command.Delete(self.pathname)
        assert(os.path.exists(self.pathname))
        from bleachbit.FileUtilities import getsize
        assert(0 == getsize(self.pathname))
        os.close(f)

        # Now that the file is not locked, admin privileges
        # are not required to delete it.
        yield Command.Delete(self.pathname)
Example #5
0
    def get_commands(self):
        # Open the file with a non-exclusive lock, so the file should
        # be truncated and marked for deletion. This is checked just on
        # on Windows.
        fd = os.open(self.pathname, os.O_RDWR)
        from bleachbit.FileUtilities import getsize
        # Without admin privileges, this delete fails.
        yield Command.Delete(self.pathname)
        assert (os.path.exists(self.pathname))
        fsize = getsize(self.pathname)
        if not fsize == 3:  # Contents is "123"
            raise RuntimeError('Locked file has size %dB (not 3B)' % fsize)
        os.close(fd)

        # Now that the file is not locked, admin privileges
        # are not required to delete it.
        yield Command.Delete(self.pathname)
Example #6
0
    def test_Chaff(self):
        """Unit test for class Chaff"""
        tmp_dir = mkdtemp(prefix='bleachbit-chaff')
        con_path = os.path.join(tmp_dir, 'content.json.bz2')
        sub_path = os.path.join(tmp_dir, 'subject.json.bz2')

        for i in ('download', 'already downloaded'):
            ret = download_models(content_model_path=con_path,
                                  subject_model_path=sub_path)
            self.assertIsInstance(ret, bool)
            self.assertTrue(ret)

        generated_file_names = generate_emails(5, con_path, sub_path, tmp_dir)

        self.assertEqual(len(generated_file_names), 5)

        for fn in generated_file_names:
            self.assertExists(fn)
            self.assertGreater(getsize(fn), 100)

        rmtree(tmp_dir)
Example #7
0
    def test_Chaff(self):
        """Unit test for class Chaff"""
        tmp_dir = mkdtemp(prefix='bleachbit-chaff')
        models_dir = os.path.join(tmp_dir, 'model')
        os.mkdir(models_dir)
        # con=Clinton content
        con_path = os.path.join(models_dir, 'clinton_content_model.json.bz2')
        # sub=Clinton subject
        sub_path = os.path.join(models_dir, 'clinton_subject_model.json.bz2')
        # ts = 2600 Magazine
        ts_path = os.path.join(models_dir, '2600_model.json.bz2')

        for _i in ('download', 'already downloaded'):
            ret = download_models(models_dir=models_dir)
            self.assertIsInstance(ret, bool)
            self.assertTrue(ret)

        self.assertExists(con_path)
        self.assertExists(sub_path)
        self.assertExists(ts_path)

        generated_file_names = generate_emails(5, tmp_dir, models_dir)

        self.assertEqual(len(generated_file_names), 5)

        for fn in generated_file_names:
            self.assertExists(fn)
            self.assertGreater(getsize(fn), 100)
            with open(fn) as f:
                contents = f.read()
                self.assertIn('To: ', contents)
                self.assertIn('From: ', contents)
                self.assertIn('Sent: ', contents)
                self.assertIn('Subject: ', contents)
                self.assertNotIn('base64', contents)

        generated_file_names = generate_2600(5, tmp_dir, models_dir)

        rmtree(tmp_dir)