Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#7521 closed (fixed)

auth/tests fail on custom project with "manage.py test"

Reported by: anonymous Owned by: telenieko
Component: Testing framework Version: 1.1-beta
Severity: Keywords: test failure
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The auth/tests.py, which evidently was added yesterday, produces some failed assertions when enacted by 'python manage.py test':

======================================================================
FAIL: test_email_found (django.contrib.auth.tests.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/tests.py", line 71, in test_email_found
    self.assertEquals(response.status_code, 302)
AssertionError: 404 != 302

======================================================================
FAIL: test_email_not_found (django.contrib.auth.tests.PasswordResetTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/auth/tests.py", line 64, in test_email_not_found
    self.assertEquals(response.status_code, 200)
AssertionError: 404 != 200

----------------------------------------------------------------------

Attachments (1)

7521.diff (6.0 KB) - added by telenieko 7 years ago.
Patch to allow "urls" parameter on tests.

Download all attachments as: .zip

Change History (18)

comment:1 Changed 7 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I'm not seeing this failure and the buildbot agrees. As at [7722], there is a failure in the tests, but it is in a different test to the one you are reporting.

comment:2 Changed 7 years ago by telenieko

  • Component changed from Authentication to Unit test system
  • milestone set to 1.0 alpha
  • Resolution worksforme deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

Not exacly, If you run "./manage.py test" on a project which has contrib.auth in INSTALLED_APPS, django will run the contrib.auth tests, and the urls.py required by those tests is not included in this case (the needed urls.py will only be included if you are running with runtests.py)

So anybody using the test framework on his project, whith contrib.auth installed is likely to have problems.

An option would be the TestCase of contrib.auth to add the needed URL's on setUp().

comment:3 Changed 7 years ago by telenieko

  • Summary changed from auth/tests fails to auth/tests fail on custom project with "manage.py test"

comment:4 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [7726]) Fixed #7521 -- Reverted [7716]. Fixed URLs in test case broke any application that deployed contrib.auth.

comment:5 Changed 7 years ago by dek <dan.kelley@…>

I'm not sure if it's ok for me to add a comment to a closed issue, but I just wanted to say, as the original reporter, that

1) this works for me now

2) thanks very much for the quick bug fix

Dan.

comment:6 Changed 7 years ago by telenieko

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Accepted to Design decision needed

I don't think we should consider this fixed, the bug here is that Contrib applications cannot test their on views, because there's no guarantee that user project's will include the contrib app urls. Which will then make those tests fails (that's what happened after [7716] with contrib.auth).

And it seems reasonable that contrib apps should be able to, somehow, test their views when using runtests.py

I can think about two options right now:

  • manage.py test should not run test for contrib apps, they're already tested by runtests.py by django developers.
  • manage.py tests should, somehow, make sure the needed urls are there or disable the tests that would fail otherwise.

I'd really be on option 1, I don't see the point on running tests for contrib apps from the user project when those apps, in theory, have already been tested.

I'll post this to django-developers, and mark as DDN. Just commenting there to leave track.

comment:7 Changed 7 years ago by telenieko

  • Owner set to telenieko
  • Status changed from reopened to new
  • Triage Stage changed from Design decision needed to Accepted

Brought for discussion here seems to be consensus on providing a way for TestCases to orverride the root urlconf on setup and bring the original urlconf back on teardown.

Apparently formtools already do this.

Changed 7 years ago by telenieko

Patch to allow "urls" parameter on tests.

comment:8 Changed 7 years ago by telenieko

  • Has patch set

Attached a patch which allows a "urls" parameter on TestCase, some other things were added:

  • Added clear_url_caches() to django.core.urlresolvers (We need to clear the cache when changing URLconfs)
  • Changed formtools.tests to use the new "urls" parameter instead of it's own hack (which could break for the cache).
  • Added two TestCase to check this works, and documentation.

Note that [7716] should be brought back after this gets in, with a new urls parameter.

NOTE: Also available on git: gitweb, git

comment:9 Changed 7 years ago by telenieko

The diff for getting back [7716] using the urls parameter is here. I'll attach if needed.

comment:10 Changed 7 years ago by garcia_marc

  • milestone changed from 1.0 alpha to 1.0

According to ticket organization defined in http://code.djangoproject.com/wiki/VersionOneRoadmap#how-you-can-help 1.0 alpha tickets should be just features in the Must have (http://code.djangoproject.com/wiki/VersionOneRoadmap#must-have-features) list.

As bug, it should be fixed before 1.0 milestone.

comment:11 Changed 7 years ago by russellm

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

(In [7805]) Fixed #7521 -- Added the ability to customize ROOT_URLCONF for the duration of a TestCase. Thanks to Mark Fargas (telenieko) for his work on this patch.

comment:12 Changed 7 years ago by russellm

(In [7808]) Refs #7521 -- Re-reverted [7716] (originally reverted in [7726]), now modified to use the new TestCase urlpattern framework.

comment:13 Changed 7 years ago by siddhi

There is still a problem here. I have the auth app installed, but I've customised the templates. It so happens that the template has a reverse lookup to some urls defined in my ROOT_URLCONF. Because the unit test case overrides my urls, the reverse lookup fails and the template rendering also fails (raises a NoReverseMatch exception) and the unit test fails.

comment:14 Changed 6 years ago by fnl

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from SVN to 1.1-beta-1

Having the same problems as siddhi. Why are the authentication tests there at all, especially, things like self.assert_("Please enter your new password" in response.content) should not be part of the base django dango distribution, at least not in the beta or stable - I'm having problems to test my apps with (1, 1, 0, 'beta', 1) because I always have to first remove the useless tests and replace them with something that works for me.

comment:15 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from reopened to closed

comment:13 seems to be reporting a version of #8404. This ticket has already been resolved. If there is a new problem that is not the same as #8404 (or some other existing ticket), please open a new ticket so that the problem tracking history is straight. Realise that "I do not think the tests for an application I have installed should be run at all" is not a bug report (comment:14). Improvements welcome; suggestions to now test things, not so much. Reclosing.

comment:16 Changed 6 years ago by fnl

Ok, sorry for adding this into the wrong ticket - moved this issue to #8404, as it fits quite well with that description. I think tests that force you to use the English language and an overly specific implementation schema should not be part of the Django base distribution (see my comments there) - however, I am not trying to say "do not run tests for installed apps" as suggested by comment:15, what I am arguing is that in the base distribution there must be a sensible amount of freedom of choice for the implementation, e.g. language and phrase usage restrictions made through tests provided by the base distribution are misplaced.

comment:17 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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