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.

Change History (1)

comment:1 by Claude Paroz, 12 years ago

Resolution: duplicate
Status: newclosed

Confirmed, the client.login method only fakes a basic request and doesn't apply the middlewares on it, hence request._messages is not set.

In the possible solutions, I see:

  • try to apply all request middlewares to the request created in login
  • special-casing (like it is done for sessions): test if messages middleware is active and manually apply MessageMiddleware.process_request to the request
  • accept the limitation and document it

After having written this, I see that this is a duplicate of #15179, which tries to go with the first solution I mentioned.

Note: See TracTickets for help on using tickets.
Back to Top