我阅读了生成单元测试的官方文档,但它太乱了。AdminPasswordChangeForm
我必须为, 和两个定义的函数生成一个单元测试用例,views.py
其中正在改变 和 的is_staff
状态is_active
。
我还编写了简单的测试用例来注册用户。Follow 是定义的方法views.py
(使用 更新密码AdminPasswordChangeForm
)
def user_change_password(request, id):
user = User.objects.get(pk=id)
form = AdminPasswordChangeForm(user, request.POST)
if form.is_valid():
new_user = form.save()
msg = _('Password changed successfully.')
request.user.message_set.create(message=msg)
return HttpResponseRedirect('../../user/users')
else:
form = AdminPasswordChangeForm(user)
extra_context = {
'form': form,
'change': True
}
return direct_to_template(request,"users/user_password_change.html",
extra_context = extra_context)