'If a session is emptied of data but still has a key, it should still
be updated.'

def test_empty_session_saved(self):

    request = RequestFactory().get('/')
    response = HttpResponse('Session    test')
    middleware = SessionMiddleware()
    middleware.process_request(request)
    request.session['foo'] = 'bar'
    response = middleware.process_response(request, response)
    self.assertEqual(tuple(request.session.items()), (('foo', 'bar'),))
    self.assertIn(('Set-Cookie:    sessionid=%s' % request.session.session_key), str(response.cookies))
    self.assertEqual(response['Vary'], 'Cookie')
    del request.session['foo']
    response = HttpResponse('Session    test')
    response = middleware.process_response(request, response)
    self.assertEqual(dict(request.session.values()), {})
    session = Session.objects.get(session_key=request.session.session_key)
    self.assertEqual(session.get_decoded(), {})
    self.assertGreater(len(request.session.session_key), 8)
    self.assertIn(('Set-Cookie:    sessionid=%s' % request.session.session_key), str(response.cookies))
    self.assertEqual(response['Vary'], 'Cookie')
