Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9868 closed (fixed)

Test client login return values should be improved

Reported by: David Sauve <dnsauve@…> Owned by: nobody
Component: Testing framework Version: 1.0
Severity: Keywords: testing test client login session
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The current implementation of the django.test.client's login method returns either True or False when trying to login a user, however, there is no way of knowing why a login failed.

The login method could probably be modified to raise an exception with further information regarding why the login failed. For example, if INSTALLED_APPS does not include 'settings'.

Change History (4)

comment:1 by David Sauve <dnsauve@…>, 16 years ago

Component: UncategorizedTesting framework

comment:2 by Eric Holscher, 16 years ago

Resolution: wontfix
Status: newclosed

I think that changing login() to raise an exception instead of returning False would be a backwards incompatibility. Testing to see if a login worked, and then if it returns false doing something else is probably used in people's test suites.

I agree that it would be nice to know why a login might fail, but I don't know if we can change this behavior without breaking pre-existing test suites.

I'm marking this wontfix, but if you can produce a patch and tests that show that this doesn't break Django's test suite, please re-open.

I changed the return False to a raise Exception, and 2 of Django's test client tests did indeed fail.

======================================================================
ERROR: Request a page that is protected with @login, but use bad credentials
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ericholscher/Python/django-trunk/tests/modeltests/test_client/models.py", line 303, in test_view_with_bad_login
    login = self.client.login(username='otheruser', password='nopassword')
  File "/Users/ericholscher/Python/django-trunk/django/test/client.py", line 408, in login
    raise Exception
Exception

======================================================================
ERROR: Request a page that is protected with @login, but use an inactive login
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ericholscher/Python/django-trunk/tests/modeltests/test_client/models.py", line 309, in test_view_with_inactive_login
    login = self.client.login(username='inactive', password='password')
  File "/Users/ericholscher/Python/django-trunk/django/test/client.py", line 408, in login
    raise Exception
Exception

----------------------------------------------------------------------
Ran 34 tests in 0.933s

comment:3 by Malcolm Tredinnick, 16 years ago

Resolution: wontfixfixed

(In [9979]) Improved table join handling for comparisons against NULL.

This fixes a broad class of bugs involving filters that look for missing
related models and fields. Most of them don't seem to have been reported
(the added tests cover the root cause). The exception is that this has
also fixed #9868.

comment:4 by Malcolm Tredinnick, 16 years ago

Ignore previous comment. I typo'd the bug number (should have been #9968).

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