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 | |
| parent | 31174031f1ded30d96c77908b965755e0be94c94 (diff) | |
Fixed #30876 -- Moved classproperty() decorator to the django.utils.functional.
Diffstat (limited to 'tests/utils_tests')
| -rw-r--r-- | tests/utils_tests/test_decorators.py | 40 | ||||
| -rw-r--r-- | tests/utils_tests/test_functional.py | 38 |
2 files changed, 38 insertions, 40 deletions
diff --git a/tests/utils_tests/test_decorators.py b/tests/utils_tests/test_decorators.py index fe5db876ef..367e78a4ad 100644 --- a/tests/utils_tests/test_decorators.py +++ b/tests/utils_tests/test_decorators.py @@ -2,7 +2,7 @@ from django.http import HttpResponse from django.template import engines from django.template.response import TemplateResponse from django.test import RequestFactory, SimpleTestCase -from django.utils.decorators import classproperty, decorator_from_middleware +from django.utils.decorators import decorator_from_middleware class ProcessViewMiddleware: @@ -108,41 +108,3 @@ class DecoratorFromMiddlewareTests(SimpleTestCase): self.assertTrue(getattr(request, 'process_response_reached', False)) # process_response saw the rendered content self.assertEqual(request.process_response_content, b"Hello world") - - -class ClassPropertyTest(SimpleTestCase): - def test_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_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) 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) |
