From 22e016ff6c18a35a450519b94de63033f83e6b4f Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Thu, 28 Feb 2008 21:24:51 +0000 Subject: gis: Merged revisions 7105-7168 via svnmerge from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7176 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/decorators/__init__.py | 0 tests/regressiontests/decorators/models.py | 2 + tests/regressiontests/decorators/tests.py | 56 ++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/regressiontests/decorators/__init__.py create mode 100644 tests/regressiontests/decorators/models.py create mode 100644 tests/regressiontests/decorators/tests.py (limited to 'tests/regressiontests/decorators') diff --git a/tests/regressiontests/decorators/__init__.py b/tests/regressiontests/decorators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regressiontests/decorators/models.py b/tests/regressiontests/decorators/models.py new file mode 100644 index 0000000000..e5a795067b --- /dev/null +++ b/tests/regressiontests/decorators/models.py @@ -0,0 +1,2 @@ +# A models.py so that tests run. + diff --git a/tests/regressiontests/decorators/tests.py b/tests/regressiontests/decorators/tests.py new file mode 100644 index 0000000000..0c434772f8 --- /dev/null +++ b/tests/regressiontests/decorators/tests.py @@ -0,0 +1,56 @@ +from unittest import TestCase +from sys import version_info + +from django.http import HttpResponse +from django.utils.functional import allow_lazy, lazy, memoize +from django.views.decorators.http import require_http_methods, require_GET, require_POST +from django.views.decorators.vary import vary_on_headers, vary_on_cookie +from django.views.decorators.cache import cache_page, never_cache, cache_control +from django.contrib.auth.decorators import login_required, permission_required, user_passes_test +from django.contrib.admin.views.decorators import staff_member_required + +def fully_decorated(request): + """Expected __doc__""" + return HttpResponse('dummy') +fully_decorated.anything = "Expected __dict__" + +# django.views.decorators.http +fully_decorated = require_http_methods(["GET"])(fully_decorated) +fully_decorated = require_GET(fully_decorated) +fully_decorated = require_POST(fully_decorated) + +# django.views.decorators.vary +fully_decorated = vary_on_headers('Accept-language')(fully_decorated) +fully_decorated = vary_on_cookie(fully_decorated) + +# django.views.decorators.cache +fully_decorated = cache_page(60*15)(fully_decorated) +fully_decorated = cache_control(private=True)(fully_decorated) +fully_decorated = never_cache(fully_decorated) + +# django.contrib.auth.decorators +fully_decorated = user_passes_test(lambda u:True)(fully_decorated) +fully_decorated = login_required(fully_decorated) +fully_decorated = permission_required('change_world')(fully_decorated) + +# django.contrib.admin.views.decorators +fully_decorated = staff_member_required(fully_decorated) + +# django.utils.functional +fully_decorated = memoize(fully_decorated, {}, 1) +fully_decorated = allow_lazy(fully_decorated) +fully_decorated = lazy(fully_decorated) + +class DecoratorsTest(TestCase): + + def test_attributes(self): + """ + Tests that django decorators set certain attributes of the wrapped + function. + """ + # Only check __name__ on Python 2.4 or later since __name__ can't be + # assigned to in earlier Python versions. + if version_info[0] >= 2 and version_info[1] >= 4: + self.assertEquals(fully_decorated.__name__, 'fully_decorated') + self.assertEquals(fully_decorated.__doc__, 'Expected __doc__') + self.assertEquals(fully_decorated.__dict__['anything'], 'Expected __dict__') -- cgit v1.3