Пример #1
0
class SimpleDatabaseClientTests(SimpleTestCase):
    def setUp(self):
        self.client = BaseDatabaseClient(connection=connection)

    def test_settings_to_cmd_args_env(self):
        msg = ('subclasses of BaseDatabaseClient must provide a '
               'settings_to_cmd_args_env() method or override a runshell().')
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.client.settings_to_cmd_args_env(None, None)
Пример #2
0
    def __init__(self, *args, **kwargs):
        self.use_transactions = kwargs.pop('use_transactions', None)

        super(DatabaseWrapper, self).__init__(*args, **kwargs)

        try:
            self.command_timeout = int(
                self.settings_dict.get('COMMAND_TIMEOUT', 30))
        except ValueError:
            self.command_timeout = 30

        options = self.settings_dict.get('OPTIONS', {})
        try:
            self.cast_avg_to_float = not bool(
                options.get('disable_avg_cast', False))
        except ValueError:
            self.cast_avg_to_float = False

        if 'use_legacy_date_fields' in options:
            warnings.warn(
                "The `use_legacy_date_fields` setting is no longer supported. "
                "If you need to use the legacy SQL 'datetime' datatype, "
                "you must replace them with the provided model fields.",
                DeprecationWarning)

        self.features = DatabaseFeatures(self)
        self.ops = DatabaseOperations(self)
        self.client = BaseDatabaseClient(self)
        self.creation = DatabaseCreation(self)
        self.introspection = DatabaseIntrospection(self)
        self.validation = BaseDatabaseValidation(self)
Пример #3
0
class SimpleDatabaseClientTests(SimpleTestCase):
    def setUp(self):
        self.client = BaseDatabaseClient(connection=connection)

    def test_settings_to_cmd_args_env(self):
        msg = ('subclasses of BaseDatabaseClient must provide a '
               'settings_to_cmd_args_env() method or override a runshell().')
        with self.assertRaisesMessage(NotImplementedError, msg):
            self.client.settings_to_cmd_args_env(None, None)

    def test_runshell_use_environ(self):
        for env in [None, {}]:
            with self.subTest(env=env):
                with mock.patch('subprocess.run') as run:
                    with mock.patch.object(
                            BaseDatabaseClient,
                            'settings_to_cmd_args_env',
                            return_value=([], env),
                    ):
                        self.client.runshell(None)
                    run.assert_called_once_with([], env=None, check=True)
Пример #4
0
 def setUp(self):
     self.client = BaseDatabaseClient(connection=connection)