Opened 7 years ago

Closed 3 years ago

#13394 closed Bug (wontfix)

django.contrib.auth.tests fail with custom Authentication Backends

Reported by: Tim Child Owned by: nobody
Component: contrib.auth Version: master
Severity: Normal Keywords: Auth, contrib, testing
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

When you are using custom Authentication backend the tests in django.contrib.auth.tests.test.FORM_TESTS fail.

FAIL: Doctest: django.contrib.auth.tests.__test__.FORM_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/test/_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for django.contrib.auth.tests.__test__.FORM_TESTS
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/tests/__init__.py", line unknown line number, in FORM_TESTS

----------------------------------------------------------------------
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/tests/__init__.py", line ?, in django.contrib.auth.tests.__test__.FORM_TESTS
Failed example:
    form.is_valid()
Expected:
    False
Got:
    403: Forbidden
    Context: user
    False

These should obviously not fail, but it would be preferable for a way to override them.

Attachments (2)

authentication_backend.patch (6.2 KB) - added by mattjmorrison 5 years ago.
changed some django.contrib tests to explicitly define which middleware classes and authentication backends are assumed to be in settings.
default_settings.diff (29.5 KB) - added by Claude Paroz 5 years ago.
Use a new DefaultSettingsTestCase

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by Tim Child

The offending test is:

{{{ # The user submits an invalid username.

data = {

... 'username': 'jsmith_does_not_exist',
... 'password': 'test123',
... }

form = AuthenticationForm(None, data)
form.is_valid()

False

form.non_field_errors()

[u'Please enter a correct username and password. Note that both fields are case-sensitive.']

}}}

comment:2 Changed 7 years ago by Russell Keith-Magee

Component: Testing frameworkContrib apps
milestone: 1.2
Triage Stage: UnreviewedAccepted

This is another example of the wider problem of "integration vs application tests". The test's dependence on an external setting environment means that local application conditions can make the test fail.

Yes, it's annoying, but it's not alone. There are a couple of other places where similar test failures occur. We need address the general problem, but it not critical for 1.2.

comment:3 Changed 6 years ago by Gabriel Hurley

Component: Contrib appscontrib.auth

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

Changed 5 years ago by mattjmorrison

changed some django.contrib tests to explicitly define which middleware classes and authentication backends are assumed to be in settings.

comment:5 Changed 5 years ago by Julien Phalip

Easy pickings: unset
UI/UX: unset

See also #17194.

Changed 5 years ago by Claude Paroz

Attachment: default_settings.diff added

Use a new DefaultSettingsTestCase

comment:6 Changed 5 years ago by Claude Paroz

Has patch: set

I'm resubmitting the (refreshed) patch that I proposed for #17194, with the idea of a DefaultSettingsTestCase to isolate the app tests from any current project settings.

comment:7 Changed 3 years ago by Tim Graham

Patch needs improvement: set

This seems like a good idea to me; patch needs to be updated to apply cleanly though.

#20796 was a recent a duplicate.

comment:8 Changed 3 years ago by Russell Keith-Magee

Isn't this a moot point once 1.6 lands? Django's new unittest discovery mechanism means that auth tests won't be run as part of an end-developer's test suite, so the we don't have to be quite as concerned about adapting to every possible environmental configuration.

comment:9 Changed 3 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

Ah, didn't realize that Russ, thanks!

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