Opened 13 years ago
Closed 13 years ago
#17194 closed Bug (fixed)
Auth tests failing on non-US locales
Reported by: | Henrique C. Alves | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Auth tests are failing on current trunk (1.4). An error message is being compared as a test condition, but this fails since the error message will return a translated string (in this particular case, pt_br).
Destroying old test database 'default'... ..........F ====================================================================== FAIL: test_inactive_user (django.contrib.auth.tests.forms.AuthenticationFormTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/hcalves/.virtualenvs/omelete.v2/src/django/django/contrib/auth/tests/forms.py", line 105, in test_inactive_user [u'This account is inactive.']) AssertionError: [u'Esta conta est\xe1 inativa.'] != [u'This account is inactive.']
Attachments (5)
Change History (16)
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Has patch: | set |
---|
Here's my proposal to fix it. Just setting LANGUAGE_CODE isn't sufficient to change current language, that's why I changed override_settings to special-case LANGUAGE_CODE setting change. Might be useful in other tests, too.
The other solution would be to enclose each string comparison test with translation.override, but it seems not very DRY to me.
by , 13 years ago
Attachment: | 17194-2.diff added |
---|
Add middleware isolation for test_session_not_accessed
comment:3 by , 13 years ago
After discussion with Julien on irc, I've come with a radically different approach, with a new DefaultSettingsTestCase class that strives to completely isolate the contrib.auth tests from custom project settings.
comment:4 by , 13 years ago
follow-up: 6 comment:5 by , 13 years ago
The patch only overrides the locale for Django's own tests, correct? User-provided tests will still run on the settings.py locale?
comment:6 by , 13 years ago
Replying to hcarvalhoalves:
The patch only overrides the locale for Django's own tests, correct? User-provided tests will still run on the settings.py locale?
Yes, of course.
comment:7 by , 13 years ago
Hm, I'm not sure why another test case class is needed, mind elaborating? I always thought @override_settings
and self.settings()
would be enough, isolating test classes has worked elsewhere, so why shouldn't it here?
comment:8 by , 13 years ago
With @override_settings and self.settings(), the logic is "Current settings except this one and this one". You never really no if suddenly a new different setting has a new side effect.
With this class, the logic is reversed. Default settings are the base (sort of a sandbox), and you only specify the particular settings (if any) which you want to specifically test.
There are pros and cons, as usual. The DefaultSettingsTestCase approach does address the specific issue of being able to test with a known and stable set of settings. Whether it is wanted or not, that's a design decision.
comment:9 by , 13 years ago
Let me propose another approach. Instead of setting fixed locale for auth tests, use localized strings in tests instead. Patch attached below does exactly that.
by , 13 years ago
Attachment: | auth-tests-localization.diff added |
---|
Another approach: localize strings in tests instead of setting fixed locale
comment:10 by , 13 years ago
If you go that approach, it might be a good idea to actually place the error messages on the relevant forms and fields so you can reuse them in the tests.
It's also better to reuse the html-escape from django (in django.utils.html) instead of creating a new one.
Attached a patch.
by , 13 years ago
Attachment: | django-17194-localise-auth-tests.patch added |
---|
That's right, multiple tests are failing when the project's
settings.LANGUAGE_CODE
isn't English. Those tests need to be made more isolated by temporarily overriding the locale. Would you like to provide a patch?