From 7dd0ceba2e8413d79c2aaff62733f4631cd3c1e7 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sat, 18 Feb 2012 13:37:30 +0000 Subject: Fixed #17720 -- Stopped the LocaleMiddleware from overeagerly using the request path for language activation if it's actually not wanted. Thanks to Anssi Kääriäinen for the initial patch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@17547 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/i18n/patterns/tests.py | 14 ++++++++++++++ tests/regressiontests/i18n/patterns/urls/path_unused.py | 10 ++++++++++ tests/regressiontests/i18n/tests.py | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/regressiontests/i18n/patterns/urls/path_unused.py (limited to 'tests') diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py index 40a62d4fb6..1cc4520358 100644 --- a/tests/regressiontests/i18n/patterns/tests.py +++ b/tests/regressiontests/i18n/patterns/tests.py @@ -78,6 +78,20 @@ class URLDisabledTests(URLTestCaseBase): self.assertEqual(reverse('prefixed'), '/prefixed/') +class PathUnusedTests(URLTestCaseBase): + """ + Check that if no i18n_patterns is used in root urlconfs, then no + language activation happens based on url prefix. + """ + urls = 'regressiontests.i18n.patterns.urls.path_unused' + + def test_no_lang_activate(self): + response = self.client.get('/nl/foo/') + self.assertEqual(response.status_code, 200) + self.assertEqual(response['content-language'], 'en') + self.assertEqual(response.context['LANGUAGE_CODE'], 'en') + + class URLTranslationTests(URLTestCaseBase): """ Tests if the pattern-strings are translated correctly (within the diff --git a/tests/regressiontests/i18n/patterns/urls/path_unused.py b/tests/regressiontests/i18n/patterns/urls/path_unused.py new file mode 100644 index 0000000000..1254d16c4e --- /dev/null +++ b/tests/regressiontests/i18n/patterns/urls/path_unused.py @@ -0,0 +1,10 @@ +from django.conf.urls import url +from django.conf.urls import patterns +from django.views.generic import TemplateView + + +view = TemplateView.as_view(template_name='dummy.html') + +urlpatterns = patterns('', + url(r'^nl/foo/', view, name='not-translated'), +) diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 4b543d2bbf..99a55bd24d 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -39,7 +39,7 @@ from .models import Company, TestModel from .patterns.tests import (URLRedirectWithoutTrailingSlashTests, URLTranslationTests, URLDisabledTests, URLTagTests, URLTestCaseBase, URLRedirectWithoutTrailingSlashSettingTests, URLNamespaceTests, - URLPrefixTests, URLResponseTests, URLRedirectTests) + URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests) from .test_warnings import DeprecationWarningTests -- cgit v1.3