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.' )
def test_with_logs_success(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='91162629d258a876ee994e9233b2ad87') args = ['-l'] kwargs = {'backup_file': tmp_file.name} call_command('restore', *args, **kwargs)
def test_backup_files_dir_with_older_restored_backup(self): # create an entry in restoration history with a dump created in the past RestoredBackupFactory(creation_date=(datetime.datetime.now()) - datetime.timedelta(days=2)) # create a backup files directory with tempfile.TemporaryDirectory() as tmp_dir: # create the backup file with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp_file: with zipfile.ZipFile(tmp_file, 'w', zipfile.ZIP_DEFLATED) as archive: archive.writestr('something.txt', 'Some Content Here') backup_file = RestoreCommand().parse_backup_files_dir(tmp_dir) self.assertIn(tmp_file.name, backup_file, 'Expected the backup to be chosen.')