Opened 2 years ago

Closed 2 years ago

#20275 closed Bug (duplicate)

WSGI environ variables not set for test client's login() request

Reported by: tim.dawborn@… Owned by: nobody
Component: Testing framework Version: 1.5
Severity: Normal Keywords:
Cc: bmispelon@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The fake HttpRequest object created in the test client's login() method does not contain any of the minimum set of WSGI environ variables defined in RequestFactory._base_environ. This becomes an issue when you have a signal receiver listening to auth.signals.user_logged_in and expecting a valid-looking request object to exist.

The specific issue I've got is that REMOTE_ADDR does not exist.

Is this a bug, or is there a reason I'm missing as to why this request object isn't valid.

Change History (3)

comment:1 Changed 2 years ago by bmispelon

  • Cc bmispelon@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I'm not sure either if this is a bug or not but in any case, it looks like a reasonable request.

From a quick look, it seems like it wouldn't be too hard to achieve by changing this line: https://github.com/django/django/blob/master/django/test/client.py#L542 to something like request = self.request().

comment:2 Changed 2 years ago by tim.dawborn@…

Yup, that was what I was going to suggest if the request seemed reasonable. I just thought it was a bit hard to believe that this hadn't been an issue for anyone else before.

comment:3 Changed 2 years ago by bmispelon

  • Resolution set to duplicate
  • Status changed from new to closed

Well it turns out this issue has been discovered before (sorry, I should have checked first): #15179.

I'm closing this one as a duplicate.

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