Django 1.4 has a expected behavior when you create the request with RequestFactory that can trigger this error.
To resolve this issue, create your request with RequestFactory and do this:
from django.contrib.messages.storage.fallback import FallbackStorage
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
Works for me!
Related Contents:
- How can I call a custom Django manage.py command directly from a test driver?
- How to spread django unit tests over multiple files?
- How do I import the Django DoesNotExist exception?
- how to unit test file upload in django
- Disable migrations when running unit tests in Django 1.7
- How do you skip a unit test in Django?
- Django’s self.client.login(…) does not work in unit tests
- Different db for testing in Django?
- Django test RequestFactory vs Client
- Detect django testing mode
- How to write a unit test for a django view?
- django – how to detect test environment (check / determine if tests are being run)
- Django override default form error messages
- Sending JSON using the django test client
- Loading fixtures in django unit tests
- Organizing Django unit tests
- How do I unit test django urls?
- Unit Testing a Django Form with a FileField
- testing admin.ModelAdmin in django
- Is APITest with Query params different then just normal url?
- Django testing rest-framework: APIRequestFactory vs APIClient
- Disable Django South when running unit tests?
- How to Unit test with different settings in Django?
- How to customize user profile when using django-allauth
- Django get a QuerySet from array of id’s in specific order
- In a Django QuerySet, how to filter for “not exists” in a many-to-one relationship
- django – get() returned more than one topic
- How do I make uWSGI restart when a Python script is modified?
- Limit foreign key choices in select in an inline form in admin
- ImportError: Couldn’t import Django
- Django : Is it impossible to static tag into block tag?
- Django: Query using contains each value in a list
- What is a good value for CONN_MAX_AGE in Django?
- Test that user was logged in successfully
- Django data migration when changing a field to ManyToMany
- Empty Request.FILES with Django Upload forms
- Django: Populate user ID when saving a model
- Django multi-select widget?
- How do I use CreateView with a ModelForm
- “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” in django
- Django Admin: how to display properties defined on model in an inline?
- How do you run a worker with AWS Elastic Beanstalk?
- How can I correctly set DJANGO_SETTINGS_MODULE for my Django project (I am using virtualenv)?
- Django tests – patch object in all tests
- How to add an HTTP header to all Django responses
- Apache or Nginx to serve Django applications? [closed]
- Django site with 2 languages
- How can I display a Django admin inline model within a fieldset?
- Django excluding one queryset from another
- Serving gzipped content from django