﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17971	RequestFactory requests can't be used to test views that call messages.add	hoffmaje	nobody	"To reproduce the problem:

* start new project with a new app
* define a view 'my_view' that calls messages.add
* define a test for that view as follows:

{{{
#!div style=""font-size: 80%""
  {{{#!python
  def test_my_view(self):
    request = RequestFactory().get('/my_view/')
    my_view(request)

  }}}
}}}

Running the test outputs:

{{{
  File ""/usr/local/lib/python2.7/dist-packages/django/contrib/messages/api.py"",
line 22, in add_message
    raise MessageFailure('You cannot add messages without installing '
MessageFailure: You cannot add messages without installing django.contrib.messag
es.middleware.MessageMiddleware
}}}


Note: The same test passed in 1.3.

I could fix my tests, by setting:

{{{
#!div style=""font-size: 80%""
  {{{#!python
  setattr(request, 'session', 'session')
  messages = FallbackStorage(request)
  setattr(request, '_messages', messages)
  }}}
}}}
"	Bug	closed	Testing framework	1.4	Normal	wontfix	RequestFactory, MessageFailure	hoffmaje	Unreviewed	0	0	0	0	0	0
