How can I do such a typical unittest?
Posted
by Malcom.Z
on Stack Overflow
See other posts from Stack Overflow
or by Malcom.Z
Published on 2010-05-10T03:41:03Z
Indexed on
2010/05/10
3:48 UTC
Read the original article
Hit count: 359
This is a simple structure in my project:
MyAPP---
note---
__init__.py
views.py
urls.py
test.py
models.py
auth--
...
template---
auth---
login.html
register.html
note---
noteshow.html
media---
css---
...
js---
...
settings.py
urls.py
__init__.py
manage.py
I want to make a unittest which can test the noteshow page working propeyly or not.
The code:
from django.test import TestCase
class Note(TestCase):
def test_noteshow(self):
response = self.client.get('/note/')
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, '/note/noteshow.html')
The problem is that my project include an auth mod, it will force the unlogin user redirecting into the login.html page when they visit the noteshow.html.
So, when I run my unittest, in the bash it raise an failure that the response.status_code is always 302 instead of 200.
All right though through this result I can check the auth mod is running well, it is not like what I want it to be.
OK, the question is that how can I make another unittest to check my noteshow.template is used or not?
Thanks for all.
django version: 1.1.1
python version: 2.6.4
Use Eclipse for MAC OS
© Stack Overflow or respective owner