3π
β
The HTTP code 302 means that your server is sending a redirect response. You should tell your client to follow redirects so that you deal with the actual login page. You can change your get
call like this:
response = c.get('/classroom/', follow=True, **auth_headers)
If you want to check the intermediate redirection steps you can inspect response.redirect_chain
. It is all documented here.
π€Louis
1π
Did you try creating a user and calling the login
method of your Client
instance?
import base64
from django.test import TestCase
class TestUsingCorrectTemplates(TestCase):
def setUp(self):
# Create your user here
# self.user = ...
def test_correct_classroom_template_used(self):
self.client.login('admin@dot.com', 'admin')
response = self.client.get('/classroom/') # XXX: You should use url reversal here.
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'classroom.html')
π€Simon Charette
- [Django]-Django: group items by foreign key
- [Django]-Amazon EC2 Deployment Not Working When IP Address Typed Into Browser Suspect Ngnix Problems
- [Django]-Queryset is evaluated when sliced?
Source:stackexchange.com