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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleSetting 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