这是我项目中的一个简单结构:
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
我想做一个单元测试,它可以测试noteshow页面是否正常工作。
编码:
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')
问题是我的项目包含一个身份验证模块,当他们访问 noteshow.html 时,它将强制取消登录用户重定向到 login.html 页面。
因此,当我运行我的单元测试时,在 bash 中会引发 response.status_code 始终为 302 而不是 200 的故障。
好吧,虽然通过这个结果我可以检查 auth mod 运行良好,但它不像我想要的那样。
好的,问题是我怎样才能进行另一个单元测试来检查我的noteshow.template是否被使用?
谢谢大家。
django 版本:1.1.1
蟒蛇版本:2.6.4
将 Eclipse 用于 MAC 操作系统