#20916: Provide a "simple_login" feature for the test client -----------------------------------+------------------------------------ Reporter: mjtamlyn | Owner: alasdair Type: New feature | Status: assigned Component: Testing framework | Version: master Severity: Normal | Resolution: Keywords: auth | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -----------------------------------+------------------------------------
Comment (by alasdair): I had a go at this ticket at the Djangoweekend sprints. You can see my work so far in my branch on github: https://github.com/alasdairnicol/django/compare/ticket_20916. I'd welcome any comments, either here or on github. As mjtamlyn says, authentication credentials are passed to the authenticate method, which makes it tricky to add the desired functionality to the existing `login` method. We could change the function signature to {{{ def login(*args, **kwargs): if args: user = args[0] else: # use credentials credentials = **kwargs }}} but it feels hacky, so I decided to try implementing a new method `simple_login`. I found that we have to specify ``user.backend``, even though the authentication backend is not used to log the user in. I have documented that `backend` must be in `AUTHENTICATION_BACKENDS` (if not, `simple_login` currently returns True, but any requests to a login protected view will be redirected to the login page). Perhaps I should raise a `ValueError` if the backend is not in `AUTHENTICATION_BACKENDS`. -- Ticket URL: <https://code.djangoproject.com/ticket/20916#comment:5> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/066.c6ae07de6585a6fa227af82abfea2985%40djangoproject.com. For more options, visit https://groups.google.com/groups/opt_out.