예제 #1
0
    def test_with_logs_failure(self, fake_confirm):

        # create the backup file
        with tempfile.NamedTemporaryFile() as tmp_file:
            with zipfile.ZipFile(tmp_file, 'w',
                                 zipfile.ZIP_DEFLATED) as archive:
                archive.writestr('something.txt', 'Some Content Here')

            # create an entry in restoration history with the same dump's hash
            RestoredBackupFactory(archive_md5=md5_file_hash(tmp_file.name))

            args = ['-l']
            kwargs = {
                'backup_file':
                tmp_file.name,
                'config':
                os.path.join(os.path.dirname(os.path.abspath(__file__)), '..',
                             'management/commands/settings_sample.ini')
            }

            with self.assertRaises(RuntimeError) as exc:
                call_command('restore', *args, **kwargs)

            self.assertIn(
                'Backup archive has already been restored',
                exc.exception.args[0],
                '"Backup archive has already been restored" exception expected.'
            )
예제 #2
0
    def test_backup_hash_success(self):

        # create the backup file
        with tempfile.NamedTemporaryFile() as tmp_file:
            with zipfile.ZipFile(tmp_file, 'w',
                                 zipfile.ZIP_DEFLATED) as archive:
                archive.writestr('something.txt', 'Some Content Here')

            # create a md5 hash file for the backup temporary file
            tmp_hash_file = tmp_file.name + '.md5'
            with open(tmp_hash_file, 'w') as hash_file:
                hash_file.write(md5_file_hash(tmp_file.name))

            try:
                file_hash = RestoreCommand().validate_backup_file_hash(
                    tmp_file.name)

                self.assertIsNotNone(
                    file_hash,
                    'Expected the backup file MD5 hash to be returned.')

            finally:
                # remove temporary hash file
                os.remove(tmp_hash_file)