This works
def 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()
response = self.client.get(reverse('home'))
But this
def test_access_to_home_with_location(self):
session = self.client.session
session['location'] = [42]
session.save()
response = self.client.get(reverse('home'))
breaks with
======================================================================
ERROR: test_access_to_home_with_location (posts.tests.HomeViewTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests.py", line 32, in test_access_to_home_with_location
session.save()
AttributeError: 'dict' object has no attribute 'save'
So it seems with out calling self.client.login()
self.client.session
is just an empty dictionary. Is there a way to initialize it as a session object?