Opened 12 years ago
Closed 12 years ago
#18973 closed Bug (duplicate)
Tests fail with login signal receiver which posts messages
Reported by: | Mitar | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | mmitar@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have login signal receiver which posts a message:
@dispatch.receiver(auth_signals.user_logged_in) def user_login_message(sender, request, user, **kwargs): messages.success(request, _("You have been successfully logged in."))
And in tests I want to create an authenticated client:
self.client = client.Client() self.client.login(username=self.user_username, password=self.user_password)
But this fails as messages framework is not enabled at that point in the code.
Note:
See TracTickets
for help on using tickets.
Confirmed, the
client.login
method only fakes a basic request and doesn't apply the middlewares on it, hencerequest._messages
is not set.In the possible solutions, I see:
MessageMiddleware.process_request
to the requestAfter having written this, I see that this is a duplicate of #15179, which tries to go with the first solution I mentioned.