Opened 5 years ago

Closed 2 years ago

#13394 closed Bug (wontfix)

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

Reported by: timc3 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 4 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 claudep 4 years ago.
Use a new DefaultSettingsTestCase

Download all attachments as: .zip

Change History (11)

comment:1 Changed 5 years ago by timc3

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 5 years ago by russellm

  • Component changed from Testing framework to Contrib apps
  • milestone 1.2 deleted
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.auth

comment:4 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 4 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 4 years ago by julien

  • Easy pickings unset
  • UI/UX unset

See also #17194.

Changed 4 years ago by claudep

Use a new DefaultSettingsTestCase

comment:6 Changed 4 years ago by claudep

  • 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 2 years ago by timo

  • 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 2 years ago by russellm

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 2 years ago by timo

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

Ah, didn't realize that Russ, thanks!

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