Code

#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.

Attachments (0)

Change History (1)

comment:1 Changed 20 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.