def test_authenticated(self):
        request = self.get_request()
        user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
            
        # at this point, trying to access a users timezone should result
        # in it created one with them in the default
        default_tz = getattr(settings, 'TIME_ZONE', 'GMT')
        self.assertEqual(default_tz, user.tz)
        
        # replace our anonymous user with a real one
        request.user = user

        mw = TimezonesMiddleware()
    
        # still need a cookie to kick this party off        
        request.COOKIES = {
            'timezone' : 'Australia/Victoria'
        }

        # process our request
        mw.process_request(request)
        
        # our stored timezone should match what the cookie was
        stored_user = User.objects.get(username = 'john')
        self.assertEqual(stored_user.tz, request.COOKIES['timezone'])

        # our session store should also reflect the same
        self.assertEqual(request.session.get('timezone'), request.COOKIES['timezone'])
Testing authenticated users with a session store
dataset/ETHPy150Open jamesmfriedman/django-easytz/easytz/tests.py/TimezoneTestCase.test_authenticated