Quantcast
Channel: Setting a session variable in django tests - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Brachamul for Setting a session variable in django tests

Please note that workarounds are no longer necessary. The original question's snippet which did not work should now work :session = self.client.sessionsession['location'] =...

View Article


Answer by Jonathan Cox for Setting a session variable in django tests

I used RequestFactory to generate a request object, set the session values manually, and passed it to the view function, as laid out in the docs.from django.test import TestCase, RequestFactoryfrom...

View Article


Answer by Ben for Setting a session variable in django tests

rzetterberg answer is the more rigorous one so I think it should remain accepted, but this way looks like it will also workdef setUp(self):""" set up sessions for anonymous users""" engine =...

View Article

Answer by rzetterberg for Setting a session variable in django tests

When no cookies are set in the client the session property is a empty dict, hence your error. Here is the relevant source of django.test.client.Client:def _session(self):""" Obtains the current session...

View Article

Setting a session variable in django tests

This worksdef test_access_to_home_with_location(self): self.client.login(username=self.user.get_username(), password='pass') session = self.client.session session['location'] = [42] session.save()...

View Article

Browsing latest articles
Browse All 5 View Live


Latest Images