Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So i'm trying to test deleting a post using Django rest as my backend.

my post view is using RetrieveUpdateDestroyAPIView which enable me to use GET, PUT and DELETE requests.

but for some reason I get a testing error saying: Method Not Allowed

@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}/
question from:https://stackoverflow.com/questions/65648694/error-405-testing-delete-request-using-pytest

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
854 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...