In my view.py I have the following check on several consecutive pages:
if(request.META.get('HTTP_REFERER') != request.build_absolute_uri(reverse('page1'))):
return redirect('page1')
This is performed on every page, checking that the user was redirected from the previous page, so (for example), if a user tries to enter the url for page4 in the address bar, the test will fail and he will be sent to page3, then that pages test will fail and he will fall back to page2, and so on.
Im doing this because I have several pages linked together which users must visit consecutively.
The problem comes when I want to unit test. The following test would throw an error because it fails the redirect test and therefore cannot test the logic of the page which im trying to test:
def test_user_information_updated_on_validation_success(self):
user = User.objects.create_superuser('username')
self.client.force_login(user)
self.client.post(reverse('page_4'), {
'exampleQuestion': 'exampleAnswer'
})
user.refresh_from_db()
self.assertEqual(user.exampleform.somefield, 'exampleAnswer')
How can I access the page within a unit test as if it had been redirected.
Thank you.