Ticket #12049: user-query-test.diff

File user-query-test.diff, 1.5 KB (added by Christian Hammond, 15 years ago)

Test case for building a query with a wrapped User.

  • tests/regressiontests/context_processors/tests.py

     
    33"""
    44
    55from django.conf import settings
     6from django.contrib.auth.models import Group
     7from django.db.models import Q
    68from django.test import TestCase
    79from django.template import Template
    810
     
    8183        self.assertContains(response, "username: super")
    8284        # bug #12037 is tested by the {% url %} in the template:
    8385        self.assertContains(response, "url: /userpage/super/")
     86
     87        # See if this object can be used for queries where a Q() comparing
     88        # a user can be used with another Q() (in an AND or OR fashion).
     89        # This simulates what a template tag might do with the user from the
     90        # context. Note that we don't need to execute a query, just build it.
     91        #
     92        # The failure case on Python 2.4 with a LazyObject-wrapped User is a
     93        # fatal TypeError: "function() takes at least 2 arguments (0 given)"
     94        # deep inside deepcopy().
     95        #
     96        # Python 2.5 and 2.6 succeed, but log internally caught exception spew:
     97        #
     98        #    Exception RuntimeError: 'maximum recursion depth exceeded while
     99        #    calling a Python object' in <type 'exceptions.AttributeError'>
     100        #    ignored"
     101        query = Q(user=response.context['user']) & Q(someflag=True)
Back to Top