Wrote a login view :
user = auth.authenticate(username=request.POST['username'],
password=request.POST['password'])
if user is not None:
if user.is_active:
auth.login(request, user)
return HttpResponseRedirect('/index/')
else:
return render_to_response('profiles/disabled.html', locals(),
RequestContext(request, {}))
If I "manually test" logging in with a disabled user I get this trace :
[21/Dec/2007 11:57:41] "GET /index HTTP/1.1" 301 0
[21/Dec/2007 11:57:41] "GET /index/ HTTP/1.1" 200 1654
[21/Dec/2007 11:57:43] "GET /profiles/login/ HTTP/1.1" 200 2040
[21/Dec/2007 11:57:53] "POST /profiles/login/ HTTP/1.1" 200 1684
and the browser shows the profiles/disabled.html page
While this test method fails:
def testLoginDisabledUser(self):
response = self.client.post('/profiles/login/', {'username':
'user', 'password': 'pass'})
self.assertEqual(response.status_code, 302)
self.assertTemplateUsed(response, 'profiles/disabled.html')
First of all I don't understand why the 302 I expected 200, put there
just to go on, and then :
self.assertTemplateUsed(response, 'profiles/disabled.html')
File "/usr/lib/python2.5/site-packages/django/test/testcases.py", line
178, in assertTemplateUsed
self.fail('No templates used to render the response')
AssertionError: No templates used to render the response
Where exactly this test is different from my manual login ? (and
therefore evidently not testing what I want ?)
(other code)
urls.py :
urlpatterns += patterns('dissipate.views',
(r'^index/$',
'index'),
)
urlpatterns += patterns('dissipate.profiles.views',
(r'^profiles/login/$',
'login'),
(r'^profiles/logout/$',
'logout'),
)
disabled.html :
{% extends "base.html" %}
{% block content %}
<p>Disabled</p>
{% endblock %}