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