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.path = None
        self.command.filename = 'foofile'
        self.command.database = TEST_MONGODB
        self.command.passphrase = None
        self.command.interactive = True
        self.command.storage = get_storage()
        self.command.connector = MongoDumpConnector()
        self.command.database_name = 'mongo'
        self.command.servername = HOSTNAME
        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.filename = 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.path = None
        self.command.filename = 'foofile'
        self.command.database = TEST_MONGODB
        self.command.passphrase = None
        self.command.interactive = True
        self.command.storage = get_storage()
        self.command.connector = MongoDumpConnector()
        self.command.database_name = 'mongo'
        self.command.servername = HOSTNAME
        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.filename = TARED_FILE
        HANDLED_FILES['written_files'].append((TARED_FILE, open(TARED_FILE, 'rb')))
        self.command._restore_backup()
        self.assertTrue(mock_runcommands.called)
Beispiel #3
0
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.filename = '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_filename(self, *args):
        # Prepare backup
        HANDLED_FILES['written_files'].append(
            (utils.filename_generate('foo'), BytesIO(b'bar')))
        # Check
        self.command.path = None
        self.command.filename = None
        self.command._restore_backup()

    def test_no_backup_found(self, *args):
        self.command.path = None
        self.command.filename = None
        with self.assertRaises(CommandError):
            self.command._restore_backup()

    def test_uncompress(self, *args):
        self.command.storage.file_read = COMPRESSED_FILE
        self.command.path = None
        self.command.filename = 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.path = None
        self.command.decrypt = True
        self.command.filename = ENCRYPTED_FILE
        HANDLED_FILES['written_files'].append(
            (ENCRYPTED_FILE, open(ENCRYPTED_FILE, 'rb')))
        self.command._restore_backup()

    def test_path(self, *args):
        self.command.path = COMPRESSED_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.filename = '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_filename(self, *args):
        # Prepare backup
        HANDLED_FILES['written_files'].append(
            (utils.filename_generate('foo'), BytesIO(b'bar')))
        # Check
        self.command.path = None
        self.command.filename = None
        self.command._restore_backup()

    def test_no_backup_found(self, *args):
        self.command.path = None
        self.command.filename = None
        with self.assertRaises(CommandError):
            self.command._restore_backup()

    def test_uncompress(self, *args):
        self.command.storage.file_read = COMPRESSED_FILE
        self.command.path = None
        self.command.filename = 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.path = None
        self.command.decrypt = True
        self.command.filename = ENCRYPTED_FILE
        HANDLED_FILES['written_files'].append((ENCRYPTED_FILE, open(ENCRYPTED_FILE, 'rb')))
        self.command._restore_backup()

    def test_path(self, *args):
        self.command.path = COMPRESSED_FILE
        self.command._restore_backup()
class DbrestoreCommandGetExtensionTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_tar(self):
        ext = self.command.get_extension('foo.tar')
        self.assertEqual(ext, '.tar')

    def test_tar_gz(self):
        ext = self.command.get_extension('foo.tar.gz')
        self.assertEqual(ext, '.gz')

    def test_no_extension(self):
        ext = self.command.get_extension('foo')
        self.assertEqual(ext, '')
Beispiel #6
0
class DbrestoreCommandGetExtensionTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_tar(self):
        ext = self.command.get_extension("foo.tar")
        self.assertEqual(ext, ".tar")

    def test_tar_gz(self):
        ext = self.command.get_extension("foo.tar.gz")
        self.assertEqual(ext, ".gz")

    def test_no_extension(self):
        ext = self.command.get_extension("foo")
        self.assertEqual(ext, "")
class DbrestoreCommandGetExtensionTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_tar(self):
        ext = self.command.get_extension('foo.tar')
        self.assertEqual(ext, '.tar')

    def test_tar_gz(self):
        ext = self.command.get_extension('foo.tar.gz')
        self.assertEqual(ext, '.gz')

    def test_no_extension(self):
        ext = self.command.get_extension('foo')
        self.assertEqual(ext, '')
Beispiel #8
0
class DbrestoreCommandGetDatabaseTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_give_db_name(self):
        db = self.command._get_database({'database': 'default'})
        self.assertEqual(db, settings.DATABASES['default'])

    def test_no_given_db(self):
        db = self.command._get_database({})
        self.assertEqual(db, settings.DATABASES['default'])

    @patch('django.conf.settings.DATABASES', {'db1': {}, 'db2': {}})
    def test_no_given_db_multidb(self):
        with self.assertRaises(CommandError):
            self.command._get_database({})
Beispiel #9
0
class DbrestoreCommandGetDatabaseTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_give_db_name(self):
        db = self.command._get_database({"database": "default"})
        self.assertEqual(db, settings.DATABASES["default"])

    def test_no_given_db(self):
        db = self.command._get_database({})
        self.assertEqual(db, settings.DATABASES["default"])

    @patch("django.conf.settings.DATABASES", {"db1": {}, "db2": {}})
    def test_no_given_db_multidb(self):
        with self.assertRaises(CommandError):
            self.command._get_database({})
class DbrestoreCommandGetDatabaseTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_give_db_name(self):
        db = self.command._get_database({'database': 'default'})
        self.assertEqual(db, settings.DATABASES['default'])

    def test_no_given_db(self):
        db = self.command._get_database({})
        self.assertEqual(db, settings.DATABASES['default'])

    @patch('django.conf.settings.DATABASES', {'db1': {}, 'db2': {}})
    def test_no_given_db_multidb(self):
        with self.assertRaises(CommandError):
            self.command._get_database({})
Beispiel #11
0
class DbrestoreCommandUncompressTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_uncompress(self):
        inputfile = open(COMPRESSED_FILE, 'rb')
        fd = self.command.uncompress_file(inputfile)
        fd.seek(0)
        self.assertEqual(fd.read(), b'foo\n')
Beispiel #12
0
class DbrestoreCommandUncompressTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()

    def test_uncompress(self):
        inputfile = open(COMPRESSED_FILE, 'rb')
        fd = self.command.uncompress_file(inputfile)
        fd.seek(0)
        self.assertEqual(fd.read(), b'foo\n')
 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()
Beispiel #14
0
class DbbackupReadLocalFileTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()
        self.command.path = '/tmp/foo.bak'

    def test_read(self):
        # setUp
        open(self.command.path, 'w').close()
        # Test
        output_file = self.command.read_local_file(self.command.path)
        # tearDown
        os.remove(self.command.path)
Beispiel #15
0
class DbbackupReadLocalFileTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()
        self.command.path = '/tmp/foo.bak'

    def test_read(self):
        # setUp
        open(self.command.path, 'w').close()
        # Test
        output_file = self.command.read_local_file(self.command.path)
        # tearDown
        os.remove(self.command.path)
Beispiel #16
0
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)
Beispiel #17
0
 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.filename = 'foofile'
     self.command.database = TEST_DATABASE
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = FakeStorage()
     self.command.connector = get_connector()
     HANDLED_FILES.clean()
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()
 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)
Beispiel #20
0
 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.filename = 'foofile'
     self.command.database = TEST_DATABASE
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = FakeStorage()
     self.command.connector = get_connector()
     HANDLED_FILES.clean()
Beispiel #21
0
 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)
Beispiel #22
0
 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 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()
Beispiel #24
0
 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.path = None
     self.command.filename = 'foofile'
     self.command.database = TEST_MONGODB
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = FakeStorage()
     self.command.connector = MongoDumpConnector()
     HANDLED_FILES.clean()
     add_private_gpg()
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()
Beispiel #26
0
 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.path = None
     self.command.filename = 'foofile'
     self.command.database = TEST_MONGODB
     self.command.passphrase = None
     self.command.interactive = True
     self.command.storage = FakeStorage()
     self.command.connector = MongoDumpConnector()
     HANDLED_FILES.clean()
     add_private_gpg()
class DbrestoreCommandDecryptTest(TestCase):
    def setUp(self):
        self.command = DbrestoreCommand()
        self.command.passphrase = None
        cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split()
        subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL)

    @patch('dbbackup.management.commands.dbrestore.input', return_value=None)
    @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")
        inputfile = open(ENCRYPTED_FILE, 'r+b')
        uncryptfile = self.command.unencrypt_file(inputfile)
        uncryptfile.seek(0)
        self.assertEqual('foo\n', uncryptfile.read())
Beispiel #28
0
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()
Beispiel #30
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.path = '/tmp/foo.bak'
Beispiel #31
0
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.filename = 'foofile'
        self.command.database = TEST_DATABASE
        self.command.passphrase = None
        self.command.interactive = True
        self.command.storage = FakeStorage()
        self.command.connector = get_connector()
        HANDLED_FILES.clean()

    def tearDown(self):
        clean_gpg_keys()

    def test_no_filename(self, *args):
        # Prepare backup
        HANDLED_FILES['written_files'].append(
            (utils.filename_generate('foo'), get_dump()))
        # Check
        self.command.path = None
        self.command.filename = None
        self.command._restore_backup()

    def test_no_backup_found(self, *args):
        self.command.path = None
        self.command.filename = None
        with self.assertRaises(CommandError):
            self.command._restore_backup()

    def test_uncompress(self, *args):
        self.command.path = None
        compressed_file, self.command.filename = utils.compress_file(get_dump(), get_dump_name())
        HANDLED_FILES['written_files'].append(
            (self.command.filename, compressed_file)
        )
        self.command.uncompress = True
        self.command._restore_backup()

    @patch('dbbackup.utils.getpass', return_value=None)
    def test_decrypt(self, *args):
        self.command.path = None
        self.command.decrypt = True
        encrypted_file, self.command.filename = utils.encrypt_file(get_dump(), get_dump_name())
        HANDLED_FILES['written_files'].append(
            (self.command.filename, encrypted_file)
        )
        self.command._restore_backup()

    def test_path(self, *args):
        temp_dump = get_dump()
        dump_path = mktemp()
        with open(dump_path, 'wb') as dump:
            copyfileobj(temp_dump, dump)
        self.command.path = dump.name
        self.command._restore_backup()
        self.command.decrypt = False
        self.command.filepath = get_dump_name()
        HANDLED_FILES['written_files'].append(
            (self.command.filepath, get_dump())
        )
        self.command._restore_backup()
Beispiel #32
0
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.filename = 'foofile'
        self.command.database = TEST_DATABASE
        self.command.passphrase = None
        self.command.interactive = True
        self.command.storage = FakeStorage()
        self.command.connector = get_connector()
        HANDLED_FILES.clean()

    def tearDown(self):
        clean_gpg_keys()

    def test_no_filename(self, *args):
        # Prepare backup
        HANDLED_FILES['written_files'].append(
            (utils.filename_generate('foo'), get_dump()))
        # Check
        self.command.path = None
        self.command.filename = None
        self.command._restore_backup()

    def test_no_backup_found(self, *args):
        self.command.path = None
        self.command.filename = None
        with self.assertRaises(CommandError):
            self.command._restore_backup()

    def test_uncompress(self, *args):
        self.command.path = None
        compressed_file, self.command.filename = utils.compress_file(
            get_dump(), get_dump_name())
        HANDLED_FILES['written_files'].append(
            (self.command.filename, compressed_file))
        self.command.uncompress = True
        self.command._restore_backup()

    @patch('dbbackup.utils.getpass', return_value=None)
    def test_decrypt(self, *args):
        self.command.path = None
        self.command.decrypt = True
        encrypted_file, self.command.filename = utils.encrypt_file(
            get_dump(), get_dump_name())
        HANDLED_FILES['written_files'].append(
            (self.command.filename, encrypted_file))
        self.command._restore_backup()

    def test_path(self, *args):
        temp_dump = get_dump()
        dump_path = mktemp()
        with open(dump_path, 'wb') as dump:
            copyfileobj(temp_dump, dump)
        self.command.path = dump.name
        self.command._restore_backup()
        self.command.decrypt = False
        self.command.filepath = get_dump_name()
        HANDLED_FILES['written_files'].append(
            (self.command.filepath, get_dump()))
        self.command._restore_backup()
Beispiel #33
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.passphrase = None
     cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split()
     subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL)
Beispiel #34
0
 def setUp(self):
     self.command = DbrestoreCommand()
Beispiel #35
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.passphrase = None
     cmd = ('gpg --import %s' % GPG_PRIVATE_PATH).split()
     subprocess.call(cmd, stdout=DEV_NULL, stderr=DEV_NULL)
 def setUp(self):
     self.command = DbrestoreCommand()
Beispiel #37
0
 def setUp(self):
     self.command = DbrestoreCommand()
     self.command.path = '/tmp/foo.bak'