I have a function view that has both a login_required and protect_csrf_cookie decorator on it (belt and suspenders). When I go to write a test for the function, I obviously have no problem logging the user in. However, I can figure out how to assign cookies to actually test the function.
Views.py
@login_required(login_url="login")
@csrf_protect
def UpdateMenu(request, slug):
"""Function for modifying Menus"""
if request.POST.get('type') == 'ajax':
return user_menu_interaction(request.user,
slug,
request.POST.get('process'))
return HttpResponseNotFound
Tests.py
def test_jg(self):
"""Test UM: updated user menu"""
csrf_client = Client(enforce_csrf_checks=True)
csrf_client.login(username='john', password='johnpassword')
response1 = csrf_client.get(f"/menu/add/{self.recipe1.slug}/")
self.assertIsInstance(response1, HttpResponseNotFound)
self.assertEqual(response1.status_code, 404)
I am hoping to get help setting the cookies on request or client objects. Any help would be greatly appreciated.