Trying to work on a project and get my head around unit Testing. I'm confused why client.get is getting a diffrent redirect than both Firefox and Chrome.
Details below, but can someone give me an idea this is occuring.
- Django Version 3
- Python verson 3.8
- Running on Ubuntu in WSL in windows.
My View Function.
class UserDashboardView(View):
def get(self, request, *args, **kwargs):
return HttpResponseRedirect('/accounts/login')
My Test Case
import unittest
from django.test import TestCase
class DashboardPageTest(TestCase):
def test_unauthenticated_user_redirected_to_login(self):
response = self.client.get('/dashboard')
print(response)
What occurs.
1 - If I go to /dashboard in Chrome and Firefox the debug shows a 302 with a location key of /accounts/login, and so the browser follows to /accounts/login
2 - If I run the unit test (python manage.py test) the print of the response returns
<HttpResponsePermanentRedirect status_code=301, "text/html; charset=utf-8", url="/dashboard/">
I have a feeling their is something I just don't get about the way the browsers vs the TestCase does redirects. Can someone please explain it?