mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #30876 -- Moved classproperty() decorator to the django.utils.functional.
This commit is contained in:
parent
31174031f1
commit
3120490912
8 changed files with 56 additions and 55 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue