'Tests that the messages API successfully falls back to using
user.message_set to store messages directly when the middleware is
disabled.'

def test_middleware_disabled_auth_user(self):

    settings.MESSAGE_LEVEL = constants.DEBUG
    user = User.objects.create_user('test', 'test@example.com', 'test')
    self.client.login(username='test', password='test')
    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)]}
    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))
        context_messages = list(response.context['messages'])
        for msg in data['messages']:
            self.assertTrue((msg in context_messages))
            self.assertContains(response, msg)
