36
38
self.assertContains(response, url)
37
39
response = self.client.post(url, {'path': '/blah/'})
38
40
self.assertContains(response, url)
42
class AuthContextProcessorTests(TestCase):
44
Tests for the ``django.contrib.auth.context_processors.auth`` processor
46
urls = 'regressiontests.context_processors.urls'
47
fixtures = ['context-processors-users.xml']
49
def test_session_not_accessed(self):
51
Tests that the session is not accessed simply by including
52
the auth context processor
54
response = self.client.get('/auth_processor_no_attr_access/')
55
self.assertContains(response, "Session not accessed")
57
def test_session_is_accessed(self):
59
Tests that the session is accessed if the auth context processor
60
is used and relevant attributes accessed.
62
response = self.client.get('/auth_processor_attr_access/')
63
self.assertContains(response, "Session accessed")
65
def test_perms_attrs(self):
66
self.client.login(username='super', password='secret')
67
response = self.client.get('/auth_processor_perms/')
68
self.assertContains(response, "Has auth permissions")
70
def test_message_attrs(self):
71
self.client.login(username='super', password='secret')
72
response = self.client.get('/auth_processor_messages/')
73
self.assertContains(response, "Message 1")
75
def test_user_attrs(self):
77
Test that the lazy objects returned behave just like the wrapped objects.
79
# These are 'functional' level tests for common use cases. Direct
80
# testing of the implementation (SimpleLazyObject) is in the 'utils'
82
self.client.login(username='super', password='secret')
83
user = authenticate(username='super', password='secret')
84
response = self.client.get('/auth_processor_user/')
85
self.assertContains(response, "unicode: super")
86
self.assertContains(response, "id: 100")
87
self.assertContains(response, "username: super")
88
# bug #12037 is tested by the {% url %} in the template:
89
self.assertContains(response, "url: /userpage/super/")
91
# See if this object can be used for queries where a Q() comparing
92
# a user can be used with another Q() (in an AND or OR fashion).
93
# This simulates what a template tag might do with the user from the
94
# context. Note that we don't need to execute a query, just build it.
96
# The failure case (bug #12049) on Python 2.4 with a LazyObject-wrapped
97
# User is a fatal TypeError: "function() takes at least 2 arguments
98
# (0 given)" deep inside deepcopy().
100
# Python 2.5 and 2.6 succeeded, but logged internally caught exception
103
# Exception RuntimeError: 'maximum recursion depth exceeded while
104
# calling a Python object' in <type 'exceptions.AttributeError'>
106
query = Q(user=response.context['user']) & Q(someflag=True)
108
# Tests for user equality. This is hard because User defines
109
# equality in a non-duck-typing way
111
self.assertEqual(response.context['user'], user)
112
self.assertEqual(user, response.context['user'])