Skip to content

Commit 8602d68

Browse files
author
Simon Willison
committed
TemplateResponse now stores Request object in _request, to avoid over-write by django.test.client.Client
1 parent 924647b commit 8602d68

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

django_openid/response.py

Lines changed: 5 additions & 2 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -67,7 +67,10 @@ def _set_content(self, value):
67
class TemplateResponse(SimpleTemplateResponse):
67
class TemplateResponse(SimpleTemplateResponse):
68

68

69
def __init__(self, request, template, context, *args, **kwargs):
69
def __init__(self, request, template, context, *args, **kwargs):
70-
self.request = request
70+
# self.request gets over-written by django.test.client.Client - and
71+
# unlike template_context and template_name the _request should not
72+
# be considered part of the public API.
73+
self._request = request
71
super(TemplateResponse, self).__init__(
74
super(TemplateResponse, self).__init__(
72
template, context, *args, **kwargs
75
template, context, *args, **kwargs
73
)
76
)
@@ -76,7 +79,7 @@ def resolve_context(self, context):
76
if isinstance(context, Context):
79
if isinstance(context, Context):
77
return context
80
return context
78
else:
81
else:
79-
return RequestContext(self.request, context)
82+
return RequestContext(self._request, context)
80

83

81
# Even less verbose alias:
84
# Even less verbose alias:
82
render = TemplateResponse
85
render = TemplateResponse

django_openid/tests/auth_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -161,4 +161,6 @@ def testRecoverAccountByUsername(self):
161
self.assertEqual(
161
self.assertEqual(
162
response.template_name, 'django_openid/recovery_complete.html'
162
response.template_name, 'django_openid/recovery_complete.html'
163
)
163
)
164+
self.assertEqual(response._request.user.username, 'noopenids')
165+
164

166

0 commit comments

Comments
 (0)