def test_get_cache_key_returns_correct_key_if_user_is_authenticated(self):
        class DummyView(object):
            throttle_scope = 'user'

        request = Request(HttpRequest())
        user = User.objects.create(username='******')
        force_authenticate(request, user)
        request.user = user
        self.throttle.allow_request(request, DummyView())
        cache_key = self.throttle.get_cache_key(request, view=DummyView())
        assert cache_key == 'throttle_user_%s' % user.pk
 def test_authenticated_user_not_affected(self):
     request = Request(HttpRequest())
     user = User.objects.create(username='******')
     force_authenticate(request, user)
     request.user = user
     assert self.throttle.get_cache_key(request, view={}) is None