diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-28 15:48:19 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-02-28 15:48:19 +0000 |
| commit | 2f2908d7b5f5e4179c6ae185e3969fd66050ad23 (patch) | |
| tree | e9243d1d90c17a167312feccd2c0dd9e25344286 /tests | |
| parent | 7c54780497aafc0749fa3f9e8d77f80e1f7b7d83 (diff) | |
queryset-refactor: Merged from trunk up to [7168].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/mutually_referential/models.py | 8 | ||||
| -rw-r--r-- | tests/regressiontests/decorators/__init__.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/decorators/models.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/decorators/tests.py | 56 |
4 files changed, 64 insertions, 2 deletions
diff --git a/tests/modeltests/mutually_referential/models.py b/tests/modeltests/mutually_referential/models.py index 7cf7bf8bb2..5176721f3d 100644 --- a/tests/modeltests/mutually_referential/models.py +++ b/tests/modeltests/mutually_referential/models.py @@ -1,18 +1,22 @@ """ 24. Mutually referential many-to-one relationships -To define a many-to-one relationship, use ``ForeignKey()`` . +Strings can be used instead of model literals to set up "lazy" relations. """ from django.db.models import * class Parent(Model): name = CharField(max_length=100, core=True) + + # Use a simple string for forward declarations. bestchild = ForeignKey("Child", null=True, related_name="favoured_by") class Child(Model): name = CharField(max_length=100) - parent = ForeignKey(Parent) + + # You can also explicitally specify the related app. + parent = ForeignKey("mutually_referential.Parent") __test__ = {'API_TESTS':""" # Create a Parent diff --git a/tests/regressiontests/decorators/__init__.py b/tests/regressiontests/decorators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/regressiontests/decorators/__init__.py 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('<html><body>dummy</body></html>') +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__') |
