I am learning how to make an api endpoint and I am trying to write a test to see if a post request returns a 200 status code. I plan on writing more tests to see if the endpoint is returning all the expected results as well. I keep getting a 403 status code and I think it is because I need to include a csrf token in the post data. What is a good way to test a POST endpoint in django?
my Test:
from django.test import TestCase
from app import settings
import requests
class ProjectEndpoint(TestCase):
def post_endpoint(self):
data = {'hello':'23'}
post_project = requests.post(settings.BASE_URL+'/api/project', params=data)
self.assertEqual(post_endpoint.status_code, 200)
This test keeps failing with 403 != 200
I think it is because the view is protected against csrf attacks, but I am really not sure. Appreciate any insight that someone has.