pytest - 误解了,来自文档Pytest授权的一个例子
问题描述
我决定看一下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)
解决方案
推荐阅读
- javascript - 从客户端状态的成员计数中过滤掉机器人
- python - 迭代纸浆约束中的可能选项列表
- math - 汇编中的定点乘法(x86)
- azure - Azure SDK for Go - 从 compute.VirtualMachine 获取 VM 资源组
- c++ - 如何编写一个包含remeoveFirstQ、insertFirstQ、removeEndQ和insertEndQ方法的循环队列类(c++)
- prolog - 如何使用 fd 求解器确定列表中的哪些元素可以求和为给定数字?
- mongodb - Mongo Collection Java- 使用对象更新
- swift - Swift Concurrency - 如何从不工作的任务中获取结果
- c# - Wrong id generation with Postgres
- python - Issue with VSC (Zero knowledge of coding)