﻿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
34730	Add an assertMessages assertion	François Freitag	François Freitag	"Most projects I’ve worked on used the messages framework, and many of them were repeating some boilerplate in the form described in https://stackoverflow.com/questions/2897609/how-can-i-unit-test-django-messages.

{{{#!python
from django.contrib.messages import get_messages

messages = list(get_messages(response.wsgi_request))
self.assertEqual(len(messages), 1)
self.assertEqual(str(messages[0]), 'my message')
}}}


I see several small pain points in this code:
- accessing `response.wsgi_request`, because get_messages needs a `request` but all we have is a response.
- `get_messages` returns an iterator, that must be consumed to perform assertions, hence the casting to a list
- the expectation lacks precision (missing the level) and clarity (in intent, and when failures are reported)
- it’s boilerplate-ish


Maybe adding an assertion to facilitate this test would benefit the other projects.

The code is small enough that it won’t be worth pulling down as a 3rd party package, especially since it requires changing the base test class over the entire test suite."	New feature	closed	contrib.messages	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
