def login_user(request):
if request.method == "POST":
username = request.POST['username'] #this is my first field to be tested
password = request.POST['password'] #this is my second field to be tested
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
playlists = Playlist.objects.filter(user=request.user)
return render(request, 'index.html', {'playlists': playlists})
else:
return render(request, 'login.html', {'error_message': 'Invalid login'})
return render(request, 'login.html')
user7029248
问问题
53 次
1 回答
1
如果要测试整个视图,可以查看:
https://docs.djangoproject.com/en/1.10/topics/testing/advanced/
基本上,您可以编写一个测试,在该视图上使用 POST 方法发送一个虚拟请求,然后通过检查响应进行验证。
于 2017-04-05T05:15:34.740 回答