'Makes sure that a login rotates the currently-used CSRF token.'

def test_login_csrf_rotate(self, password='password'):

    req = HttpRequest()
    CsrfViewMiddleware().process_view(req, login_view, (), {})
    req.META['CSRF_COOKIE_USED'] = True
    resp = login_view(req)
    resp2 = CsrfViewMiddleware().process_response(req, resp)
    csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
    token1 = csrf_cookie.coded_value
    req = HttpRequest()
    req.COOKIES[settings.CSRF_COOKIE_NAME] = token1
    req.method = 'POST'
    req.POST = {'username': 'testclient', 'password': password, 'csrfmiddlewaretoken': token1}
    req.REQUEST = req.POST
    SessionMiddleware().process_request(req)
    CsrfViewMiddleware().process_view(req, login_view, (), {})
    req.META['SERVER_NAME'] = 'testserver'
    req.META['SERVER_PORT'] = 80
    resp = login_view(req)
    resp2 = CsrfViewMiddleware().process_response(req, resp)
    csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None)
    token2 = csrf_cookie.coded_value
    self.assertNotEqual(token1, token2)
