コード例 #1
0
ファイル: systemtests.py プロジェクト: jonsim/tiny-backup
    def test_dir_full_pipeline(self):
        """Basic test of a single directory archive, encrypt and backup."""
        try:
            # Setup the test state.
            tempdir, in_dir, out_dir = self._create_tempdir_structure('input', \
                'output')
            in_struct, out_struct, cfg_file = self._create_single_dir_test(\
                'struct', 'struct.tar.xz.gpg', tempdir, in_dir, tempdir, \
                [_ConfigSection('input/struct', tempdir, archive='yes',
                                compress='yes', encrypt='yes')])
            in_dir_hash = test.get_dir_md5(in_dir)

            # Run backup.
            with redir_stdstreams() as (stdout, stderr):
                backup.main(['--config', cfg_file, '--gpg-home', test.GPG_HOME])
            self.assertEqual('', stdout.getvalue().strip())
            self.assertEqual('', stderr.getvalue().strip())

            # Assert the output state looks as we expect.
            self.assertTrue(os.path.isdir(in_struct))
            self.assertTrue(os.path.isfile(out_struct))
            self.assertEqual(in_dir_hash, test.get_dir_md5(in_dir))
            undo_out_file = os.path.join(out_dir, 'struct')
            backup.unencrypt_path(os.path.join(tempdir, 'struct.tar.xz'),
                                  out_struct, homedir=test.GPG_HOME)
            backup.uncompress_path(os.path.join(tempdir, 'struct.tar'),
                                   os.path.join(tempdir, 'struct.tar.xz'))
            backup.unarchive_path(out_dir, os.path.join(tempdir, 'struct.tar'))
            self.assertTrue(os.path.isdir(undo_out_file))
            self.assertEqual(in_dir_hash, test.get_dir_md5(out_dir))

        finally:
            shutil.rmtree(tempdir)
コード例 #2
0
ファイル: systemtests.py プロジェクト: jonsim/tiny-backup
    def test_file_archive(self):
        """Basic test of a single file archive and backup."""
        try:
            # Setup the test state.
            tempdir, in_dir, out_dir = self._create_tempdir_structure('input', \
                'output')
            in_file, out_file, cfg_file = self._create_single_file_test(\
                'file.txt', 'file.txt.tar', tempdir, in_dir, out_dir, \
                [_ConfigSection('input/file.txt', out_dir, archive='yes')])
            in_dir_hash = test.get_dir_md5(in_dir)
            in_file_hash = test.get_file_md5(in_file)

            # Run backup.
            with redir_stdstreams() as (stdout, stderr):
                backup.main(['--config', cfg_file])
            self.assertEqual('', stdout.getvalue().strip())
            self.assertEqual('', stderr.getvalue().strip())

            # Assert the output state looks as we expect.
            self.assertTrue(os.path.isfile(in_file))
            self.assertTrue(os.path.isfile(out_file))
            self.assertEqual(in_dir_hash, test.get_dir_md5(in_dir))
            undo_out_file = os.path.join(tempdir, 'file.txt')
            backup.unarchive_path(tempdir, out_file)
            self.assertTrue(os.path.isfile(undo_out_file))
            self.assertEqual(in_file_hash, test.get_file_md5(undo_out_file))

        finally:
            shutil.rmtree(tempdir)