'Tests that, when the middleware is disabled and a user is not logged
in, an exception is not raised if \'fail_silently\' = True'

def test_middleware_disabled_anon_user_fail_silently(self):

    settings.MESSAGE_LEVEL = constants.DEBUG
    settings.INSTALLED_APPS = list(settings.INSTALLED_APPS)
    settings.INSTALLED_APPS.remove('django.contrib.messages')
    settings.MIDDLEWARE_CLASSES = list(settings.MIDDLEWARE_CLASSES)
    settings.MIDDLEWARE_CLASSES.remove('django.contrib.messages.middleware.MessageMiddleware')
    settings.TEMPLATE_CONTEXT_PROCESSORS = list(settings.TEMPLATE_CONTEXT_PROCESSORS)
    settings.TEMPLATE_CONTEXT_PROCESSORS.remove('django.contrib.messages.context_processors.messages')
    data = {'messages': [('Test    message    %d' % x) for x in xrange(10)], 'fail_silently': True}
    show_url = reverse('django.contrib.messages.tests.urls.show')
    for level in ('debug', 'info', 'success', 'warning', 'error'):
        add_url = reverse('django.contrib.messages.tests.urls.add', args=(level,))
        response = self.client.post(add_url, data, follow=True)
        self.assertRedirects(response, show_url)
        self.assertTrue(('messages' in response.context))
        self.assertEqual(list(response.context['messages']), [])
