From 312049091288dbba2299de8d07ea3e3311ed7238 Mon Sep 17 00:00:00 2001 From: André Ericson Date: Fri, 18 Oct 2019 21:00:34 +0200 Subject: Fixed #30876 -- Moved classproperty() decorator to the django.utils.functional. --- tests/utils_tests/test_functional.py | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'tests/utils_tests/test_functional.py') 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) -- cgit v1.3