'Tests that ensure_csrf_cookie doesn\'t log warnings. See #19436.'

def test_ensures_csrf_cookie_no_logging(self):

    @ensure_csrf_cookie
    def view(request):
        return HttpResponse(content=u'')
    class TestHandler(logging.Handler, ):
        def emit(self, record):
            raise Exception(u"This    shouldn't    have    happened!")
    logger = logging.getLogger(u'django.request')
    test_handler = TestHandler()
    old_log_level = logger.level
    try:
        logger.addHandler(test_handler)
        logger.setLevel(logging.WARNING)
        req = self._get_GET_no_csrf_cookie_request()
        resp = view(req)
    finally:
        logger.removeHandler(test_handler)
        logger.setLevel(old_log_level)
