python – 为什么django.test.client.Client没有让我登录
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 为什么django.test.client.Client没有让我登录,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含983字,纯文字阅读大概需要2分钟。
内容图文
![python – 为什么django.test.client.Client没有让我登录](/upload/InfoBanner/zyjiaocheng/769/41818fd6c21844909f5916e861e127a9.jpg)
我正在使用django.test.client.Client来测试用户登录时是否显示某些文本.但是,我的Client对象似乎没有让我登录.
如果使用Firefox手动完成此测试,但在使用Client对象完成时则不会.
class Test(TestCase):
def test_view(self):
user.set_password(password)
user.save()
client = self.client
# I thought a more manual way would work, but no luck
# client.post('/login', {'username':user.username, 'password':password})
login_successful = client.login(username=user.username, password=password)
# this assert passes
self.assertTrue(login_successful)
response = client.get("/path", follow=True)
#whether follow=True or not doesn't seem to work
self.assertContains(response, "needle" )
当我打印响应时,它返回隐藏的登录表单:
{% if not request.user.is_authenticated %}
... form ...
{% endif %}
当我运行ipython manage.py shell时,这已得到确认.
问题似乎是Client对象没有对会话进行身份验证.
解决方法:
FWIW,Django 1.2的更新(之前我运行的是1.1.1)修复了它.我不知道在那里打破了什么,考虑到我在大约两周前上次运行该测试套件时,它运行得很好.
内容总结
以上是互联网集市为您收集整理的python – 为什么django.test.client.Client没有让我登录全部内容,希望文章能够帮你解决python – 为什么django.test.client.Client没有让我登录所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。