如何解决错误 405 - 使用 pytest 测试 DELETE 请求
所以我正在尝试使用 Django rest 作为我的后端来测试删除帖子。
我的帖子视图正在使用 RetrieveUpdateDestroyAPIView,它使我能够使用 GET、PUT 和 DELETE 请求。
但由于某种原因,我收到一条测试错误消息:不允许使用方法
@pytest.fixture
def delete_post(api_client):
post_id = Post.objects.all()[0].id
delete_post_url = '/posts/{post_id}/'
delete_post = api_client.delete(delete_post_url)
return delete_post
@pytest.mark.django_db
def post_deleted_successfully(self,api_client,login,create_post,delete_post):
post_deleted_successfully = delete_post
assert post_deleted_successfully.status_code == 200
E assert 405 == 200
E + where 405 = <HttpResponseNotAllowed [GET,HEAD,OPTIONS] status_code=405,"text/html; charset=utf-8">.status_code
WARNING django.request:base.py:101 Method Not Allowed (DELETE): /posts/{post_id}/
WARNING django.request:log.py:224 Method Not Allowed: /recipes/{recipe_id}/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。