class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage() HANDLED_FILES.clean() cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split() subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL) def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): # Create backup HANDLED_FILES['written_files'].append( (':memory:.bak', BytesIO(b'bar'))) # Check self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE HANDLED_FILES['written_files'].append( (COMPRESSED_FILE, open(COMPRESSED_FILE, 'rb'))) self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.utils.getpass', return_value=None) def test_decrypt(self, *args): if six.PY3: self.skipTest("Decryption isn't implemented in Python3") self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE HANDLED_FILES['written_files'].append( (ENCRYPTED_FILE, open(ENCRYPTED_FILE))) self.command.restore_backup()
class DbMongoRestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = "bak" self.command.filepath = "foofile" self.command.database = TEST_MONGODB self.command.dbcommands = MongoDBCommands(TEST_MONGODB) self.command.passphrase = None self.command.interactive = True self.command.storage = FakeStorage() HANDLED_FILES.clean() add_private_gpg() def test_mongo_settings_backup_command(self, mock_runcommands, *args): self.command.storage.file_read = TARED_FILE self.command.filepath = TARED_FILE HANDLED_FILES["written_files"].append((TARED_FILE, open(TARED_FILE, "rb"))) self.command.restore_backup() self.assertTrue(mock_runcommands.called)
class DbMongoRestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_MONGODB self.command.dbcommands = MongoDBCommands(TEST_MONGODB) self.command.passphrase = None self.command.interactive = True self.command.storage = FakeStorage() HANDLED_FILES.clean() add_private_gpg() def test_mongo_settings_backup_command(self, mock_runcommands, *args): self.command.storage.file_read = TARED_FILE self.command.filepath = TARED_FILE HANDLED_FILES['written_files'].append( (TARED_FILE, open(TARED_FILE, 'rb'))) self.command.restore_backup() self.assertTrue(mock_runcommands.called)
class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.interactive = True self.command.storage = FakeStorage() HANDLED_FILES.clean() add_private_gpg() def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): # Create backup HANDLED_FILES['written_files'].append( (utils.filename_generate('foo'), BytesIO(b'bar'))) # Check self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE HANDLED_FILES['written_files'].append( (COMPRESSED_FILE, open(COMPRESSED_FILE, 'rb'))) self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.utils.getpass', return_value=None) def test_decrypt(self, *args): self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE HANDLED_FILES['written_files'].append( (ENCRYPTED_FILE, open(ENCRYPTED_FILE, 'rb'))) self.command.restore_backup()
class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage() HANDLED_FILES.clean() cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split() subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL) def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): # Create backup HANDLED_FILES['written_files'].append((':memory:.bak', BytesIO(b'bar'))) # Check self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE HANDLED_FILES['written_files'].append((COMPRESSED_FILE, open(COMPRESSED_FILE, 'rb'))) self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.utils.getpass', return_value=None) def test_decrypt(self, *args): if six.PY3: self.skipTest("Decryption isn't implemented in Python3") self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE HANDLED_FILES['written_files'].append((ENCRYPTED_FILE, open(ENCRYPTED_FILE))) self.command.restore_backup()
class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.interactive = True self.command.storage = FakeStorage() HANDLED_FILES.clean() add_private_gpg() def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): # Create backup HANDLED_FILES['written_files'].append( (utils.filename_generate('foo'), BytesIO(b'bar'))) # Check self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE HANDLED_FILES['written_files'].append((COMPRESSED_FILE, open(COMPRESSED_FILE, 'rb'))) self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.utils.getpass', return_value=None) def test_decrypt(self, *args): self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE HANDLED_FILES['written_files'].append((ENCRYPTED_FILE, open(ENCRYPTED_FILE, 'rb'))) self.command.restore_backup()
class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage() cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split() subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL) def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): self.command.storage.list_files = ['foo.bak'] self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.management.commands.dbrestore.getpass', return_value=None) def test_decrypt(self, *args): if six.PY3: self.skipTest("Decryption isn't implemented in Python3") self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE self.command.restore_backup()
class DbrestoreCommandRestoreBackupTest(TestCase): def setUp(self): self.command = DbrestoreCommand() self.command.stdout = DEV_NULL self.command.uncompress = False self.command.decrypt = False self.command.backup_extension = 'bak' self.command.filepath = 'foofile' self.command.database = TEST_DATABASE self.command.dbcommands = DBCommands(TEST_DATABASE) self.command.passphrase = None self.command.storage = FakeStorage() cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split() subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL) def tearDown(self): clean_gpg_keys() def test_no_filepath(self, *args): self.command.storage.list_files = ['foo.bak'] self.command.filepath = None self.command.restore_backup() def test_no_backup_found(self, *args): self.command.filepath = None with self.assertRaises(CommandError): self.command.restore_backup() def test_uncompress(self, *args): self.command.storage.file_read = COMPRESSED_FILE self.command.filepath = COMPRESSED_FILE self.command.uncompress = True self.command.restore_backup() @patch('dbbackup.management.commands.dbrestore.getpass', return_value=None) def test_decrypt(self, *args): if six.PY3: self.skipTest("Decryption isn't implemented in Python3") self.command.decrypt = True self.command.filepath = ENCRYPTED_FILE self.command.restore_backup()