diff options
| author | André Ericson <de.ericson@gmail.com> | 2019-10-18 21:00:34 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-21 09:57:39 +0200 |
| commit | 312049091288dbba2299de8d07ea3e3311ed7238 (patch) | |
| tree | f279e94af6d3fe6bddb33afcb0ce8928b9cf1fd6 /tests/utils_tests/test_functional.py | |
| parent | 31174031f1ded30d96c77908b965755e0be94c94 (diff) | |
Fixed #30876 -- Moved classproperty() decorator to the django.utils.functional.
Diffstat (limited to 'tests/utils_tests/test_functional.py')
| -rw-r--r-- | tests/utils_tests/test_functional.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index af4bd197a6..6e454cfef3 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -1,7 +1,7 @@ from unittest import mock from django.test import SimpleTestCase -from django.utils.functional import cached_property, lazy +from django.utils.functional import cached_property, classproperty, lazy class FunctionalTests(SimpleTestCase): @@ -218,3 +218,39 @@ class FunctionalTests(SimpleTestCase): with mock.patch.object(__proxy__, '__prepare_class__') as mocked: lazified() mocked.assert_not_called() + + def test_classproperty_getter(self): + class Foo: + foo_attr = 123 + + def __init__(self): + self.foo_attr = 456 + + @classproperty + def foo(cls): + return cls.foo_attr + + class Bar: + bar = classproperty() + + @bar.getter + def bar(cls): + return 123 + + self.assertEqual(Foo.foo, 123) + self.assertEqual(Foo().foo, 123) + self.assertEqual(Bar.bar, 123) + self.assertEqual(Bar().bar, 123) + + def test_classproperty_override_getter(self): + class Foo: + @classproperty + def foo(cls): + return 123 + + @foo.getter + def foo(cls): + return 456 + + self.assertEqual(Foo.foo, 456) + self.assertEqual(Foo().foo, 456) |
