How can I do such a typical unittest?
- by Malcom.Z
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