1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

Fixed #21579 -- Made LocaleMiddleware respect script prefix.

Thanks buettgenbach at datacollect.com for the report and patch.
This commit is contained in:
Tim Graham
2014-08-14 09:32:50 -04:00
parent cf79b57ad0
commit fe38be96c1
2 changed files with 33 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import os
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse, clear_url_caches
from django.core.urlresolvers import reverse, clear_url_caches, set_script_prefix
from django.http import HttpResponsePermanentRedirect
from django.middleware.locale import LocaleMiddleware
from django.test import TestCase, override_settings
@@ -290,6 +290,25 @@ class URLResponseTests(URLTestCaseBase):
self.assertEqual(response.context['LANGUAGE_CODE'], 'pt-br')
class URLRedirectWithScriptAliasTests(URLTestCaseBase):
"""
#21579 - LocaleMiddleware should respect the script prefix.
"""
def setUp(self):
super(URLRedirectWithScriptAliasTests, self).setUp()
self.script_prefix = '/script_prefix'
set_script_prefix(self.script_prefix)
def tearDown(self):
super(URLRedirectWithScriptAliasTests, self).tearDown()
# reset script prefix
set_script_prefix('')
def test_language_prefix_with_script_prefix(self):
response = self.client.get('/prefixed/', HTTP_ACCEPT_LANGUAGE='en', SCRIPT_NAME=self.script_prefix)
self.assertRedirects(response, '%s/en/prefixed/' % self.script_prefix, target_status_code=404)
class URLTagTests(URLTestCaseBase):
"""
Test if the language tag works.