def test_create_dump(self, mock_dump_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Test dump
     dump_content = dump.read()
     self.assertTrue(dump_content)
     self.assertEqual(dump_content, b'foo')
     # Test cmd
     self.assertTrue(mock_dump_cmd.called)
Ejemplo n.º 2
0
 def test_create_dump(self, mock_dump_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Test dump
     dump_content = dump.read()
     self.assertTrue(dump_content)
     self.assertEqual(dump_content, b'foo')
     # Test cmd
     self.assertTrue(mock_dump_cmd.called)
 def test_restore_dump_drop(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.drop = False
     connector.restore_dump(dump)
     self.assertNotIn('--drop', mock_restore_cmd.call_args[0][0])
     # With
     connector.drop = True
     connector.restore_dump(dump)
     self.assertIn(' --drop', mock_restore_cmd.call_args[0][0])
 def test_restore_dump_object_check(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.object_check = False
     connector.restore_dump(dump)
     self.assertNotIn('--objcheck', mock_restore_cmd.call_args[0][0])
     # With
     connector.object_check = True
     connector.restore_dump(dump)
     self.assertIn(' --objcheck', mock_restore_cmd.call_args[0][0])
 def test_restore_dump_password(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.settings.pop('PASSWORD', None)
     connector.restore_dump(dump)
     self.assertNotIn(' --password ', mock_restore_cmd.call_args[0][0])
     # With
     connector.settings['PASSWORD'] = '******'
     connector.restore_dump(dump)
     self.assertIn(' --password foo', mock_restore_cmd.call_args[0][0])
 def test_restore_dump_user(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.settings.pop('USER', None)
     connector.restore_dump(dump)
     self.assertNotIn(' --username ', mock_restore_cmd.call_args[0][0])
     # With
     connector.settings['USER'] = '******'
     connector.restore_dump(dump)
     self.assertIn(' --username foo', mock_restore_cmd.call_args[0][0])
Ejemplo n.º 7
0
 def test_restore_dump_drop(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.drop = False
     connector.restore_dump(dump)
     self.assertNotIn('--drop', mock_restore_cmd.call_args[0][0])
     # With
     connector.drop = True
     connector.restore_dump(dump)
     self.assertIn(' --drop', mock_restore_cmd.call_args[0][0])
Ejemplo n.º 8
0
 def test_restore_dump_object_check(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.object_check = False
     connector.restore_dump(dump)
     self.assertNotIn('--objcheck', mock_restore_cmd.call_args[0][0])
     # With
     connector.object_check = True
     connector.restore_dump(dump)
     self.assertIn(' --objcheck', mock_restore_cmd.call_args[0][0])
Ejemplo n.º 9
0
 def test_create_dump_password(self, mock_dump_cmd):
     connector = MongoDumpConnector()
     # Without
     connector.settings.pop('PASSWORD', None)
     connector.create_dump()
     self.assertNotIn(' --password ', mock_dump_cmd.call_args[0][0])
     # With
     connector.settings['PASSWORD'] = '******'
     connector.create_dump()
     self.assertIn(' --password \'foo bar\'', mock_dump_cmd.call_args[0][0])
Ejemplo n.º 10
0
 def test_restore_dump_password(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.settings.pop('PASSWORD', None)
     connector.restore_dump(dump)
     self.assertNotIn(' --password ', mock_restore_cmd.call_args[0][0])
     # With
     connector.settings['PASSWORD'] = '******'
     connector.restore_dump(dump)
     self.assertIn(' --password foo', mock_restore_cmd.call_args[0][0])
Ejemplo n.º 11
0
 def test_restore_dump_user(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     # Without
     connector.settings.pop('USER', None)
     connector.restore_dump(dump)
     self.assertNotIn(' --username ', mock_restore_cmd.call_args[0][0])
     # With
     connector.settings['USER'] = '******'
     connector.restore_dump(dump)
     self.assertIn(' --username foo', mock_restore_cmd.call_args[0][0])
Ejemplo n.º 12
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()
 def test_restore_dump(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     connector.restore_dump(dump)
     # Test cmd
     self.assertTrue(mock_restore_cmd.called)
Ejemplo n.º 14
0
 def test_restore_dump(self, mock_dump_cmd, mock_restore_cmd):
     connector = MongoDumpConnector()
     dump = connector.create_dump()
     connector.restore_dump(dump)
     # Test cmd
     self.assertTrue(mock_restore_cmd.called)
        self.assertEqual(name, 'default')
        self.assertEqual(db, settings.DATABASES['default'])

    def test_no_given_db(self):
        name, db = self.command._get_database({})
        self.assertEqual(name, 'default')
        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({})


@patch('dbbackup.management.commands._base.input', return_value='y')
@patch('dbbackup.management.commands.dbrestore.get_connector', return_value=MongoDumpConnector())
@patch('dbbackup.db.mongodb.MongoDumpConnector.restore_dump')
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()