File: test_test_overrides.py

package info (click to toggle)
python-django-constance 4.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: python: 2,080; makefile: 25; javascript: 23; sh: 6
file content (37 lines) | stat: -rw-r--r-- 1,334 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.test import TestCase

from constance import config
from constance.test import override_config


class OverrideConfigFunctionDecoratorTestCase(TestCase):
    """
    Test that the override_config decorator works correctly.

    Test usage of override_config on test method and as context manager.
    """

    def test_default_value_is_true(self):
        """Assert that the default value of config.BOOL_VALUE is True."""
        self.assertTrue(config.BOOL_VALUE)

    @override_config(BOOL_VALUE=False)
    def test_override_config_on_method_changes_config_value(self):
        """Assert that the method decorator changes config.BOOL_VALUE."""
        self.assertFalse(config.BOOL_VALUE)

    def test_override_config_as_context_manager_changes_config_value(self):
        """Assert that the context manager changes config.BOOL_VALUE."""
        with override_config(BOOL_VALUE=False):
            self.assertFalse(config.BOOL_VALUE)

        self.assertTrue(config.BOOL_VALUE)


@override_config(BOOL_VALUE=False)
class OverrideConfigClassDecoratorTestCase(TestCase):
    """Test that the override_config decorator works on classes."""

    def test_override_config_on_class_changes_config_value(self):
        """Assert that the class decorator changes config.BOOL_VALUE."""
        self.assertFalse(config.BOOL_VALUE)