Exemple #1
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        self.assertEqual(config["handlers"]["mail_admins"]["filters"],
                         ['require_debug_false'])
Exemple #2
0
    def test_filter_configuration(self):
        """
        Test that the auto-added require_debug_false filter is an instance of
        `RequireDebugFalse` filter class.

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        flt = config["filters"]["require_debug_false"]
        self.assertEqual(flt["()"], "django.utils.log.RequireDebugFalse")
Exemple #3
0
    def test_filter_configuration(self):
        """
        Test that the auto-added require_debug_false filter is an instance of
        `RequireDebugFalse` filter class.

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        flt = config["filters"]["require_debug_false"]
        self.assertEqual(flt["()"], "django.utils.log.RequireDebugFalse")
Exemple #4
0
    def test_no_patch_if_filters_key_exists(self):
        """
        Test that the logging configuration is not modified if the mail_admins
        handler already has a "filters" key.

        """
        config = copy.deepcopy(OLD_LOGGING)
        config["handlers"]["mail_admins"]["filters"] = []
        new_config = copy.deepcopy(config)
        compat_patch_logging_config(new_config)

        self.assertEqual(config, new_config)
Exemple #5
0
    def test_no_patch_if_no_mail_admins_handler(self):
        """
        Test that the logging configuration is not modified if the mail_admins
        handler is not present.

        """
        config = copy.deepcopy(OLD_LOGGING)
        config["handlers"].pop("mail_admins")
        new_config = copy.deepcopy(config)
        compat_patch_logging_config(new_config)

        self.assertEqual(config, new_config)
Exemple #6
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        self.assertEqual(
            config["handlers"]["mail_admins"]["filters"],
            ['require_debug_false'])
Exemple #7
0
    def test_no_patch_if_no_mail_admins_handler(self):
        """
        Test that the logging configuration is not modified if the mail_admins
        handler is not present.

        """
        config = copy.deepcopy(OLD_LOGGING)
        config["handlers"].pop("mail_admins")
        new_config = copy.deepcopy(config)
        compat_patch_logging_config(new_config)

        self.assertEqual(config, new_config)
Exemple #8
0
    def test_no_patch_if_filters_key_exists(self):
        """
        Test that the logging configuration is not modified if the mail_admins
        handler already has a "filters" key.

        """
        config = copy.deepcopy(OLD_LOGGING)
        config["handlers"]["mail_admins"]["filters"] = []
        new_config = copy.deepcopy(config)
        compat_patch_logging_config(new_config)

        self.assertEqual(config, new_config)
Exemple #9
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            compat_patch_logging_config(config)
            self.assertEqual(len(w), 1)

        self.assertEqual(config["handlers"]["mail_admins"]["filters"], ["require_debug_false"])
Exemple #10
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            compat_patch_logging_config(config)
            self.assertEqual(len(w), 1)

        self.assertEqual(config["handlers"]["mail_admins"]["filters"],
                         ['require_debug_false'])
Exemple #11
0
    def test_filter_added(self):
        """
        Test that debug-false filter is added to mail_admins handler if it has
        no filters.

        """
        config = copy.deepcopy(OLD_LOGGING)

        warnings_state = get_warnings_state()
        warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.conf')
        try:
            compat_patch_logging_config(config)
        finally:
            restore_warnings_state(warnings_state)

        self.assertEqual(
            config["handlers"]["mail_admins"]["filters"],
            ['require_debug_false'])
Exemple #12
0
    def test_filter_configuration(self):
        """
        Test that the debug-false filter is a CallbackFilter with a callback
        that works as expected (returns ``not DEBUG``).

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        flt = config["filters"]["require_debug_false"]

        self.assertEqual(flt["()"], "django.utils.log.CallbackFilter")

        callback = flt["callback"]

        with self.settings(DEBUG=True):
            self.assertEqual(callback("record is not used"), False)

        with self.settings(DEBUG=False):
            self.assertEqual(callback("record is not used"), True)
Exemple #13
0
    def test_filter_configuration(self):
        """
        Test that the debug-false filter is a CallbackFilter with a callback
        that works as expected (returns ``not DEBUG``).

        """
        config = copy.deepcopy(OLD_LOGGING)
        compat_patch_logging_config(config)

        flt = config["filters"]["require_debug_false"]

        self.assertEqual(flt["()"], "django.utils.log.CallbackFilter")

        callback = flt["callback"]

        with self.settings(DEBUG=True):
            self.assertEqual(callback("record is not used"), False)

        with self.settings(DEBUG=False):
            self.assertEqual(callback("record is not used"), True)