问题描述
我决定看Pytest,马上就误会了,文档中的一个例子,但是没有授权,测试崩溃,代码是301,有谁知道是什么原因?
def test_with_authenticated_client(client,django_user_model):
username = "TestUser"
password = "1234567"
user = django_user_model.objects.create_user(username=username,password=password)
# Use this:
client.force_login(user)
response = client.get('/new')
assert response.status_code == 200
def test_with_authenticated_client2(client):
username = "user2"
password = "bar"
# Or this:
client.login(username=username,password=password)
response = client.get('/new')
assert response.status_code == 200
使用未经授权的客户端,预期代码 301
def test_make_not_authorized_user(client):
response = client.get('/new')
assert response.status_code in (302,301)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)