Ticket #17555: 17555.diff

File 17555.diff, 2.4 KB (added by gabooo, 13 years ago)

Tests added

  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 28d2012..419b380 100644
    a b accept_language_re = re.compile(r'''  
    3838        (?:\s*,\s*|$)                                 # Multiple accepts per header.
    3939        ''', re.VERBOSE)
    4040
    41 language_code_prefix_re = re.compile(r'^/([\w-]+)/')
     41language_code_prefix_re = re.compile(r'^/([\w-]+)(/|$)')
    4242
    4343def to_locale(language, to_lower=False):
    4444    """
  • tests/regressiontests/utils/tests.py

    diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py
    index f5ca06e..0e34651 100644
    a b from .timezone import TimezoneTests  
    2626from .crypto import TestUtilsCryptoPBKDF2
    2727from .archive import TestZip, TestTar, TestGzipTar, TestBzip2Tar
    2828from .regex_helper import NormalizeTests
     29from .translation import TranslationI18nEnabledTests, TranslationI18nDisabledTests
  • new file tests/regressiontests/utils/translation.py

    diff --git a/tests/regressiontests/utils/translation.py b/tests/regressiontests/utils/translation.py
    new file mode 100644
    index 0000000..c3666ed
    - +  
     1from django.test import TestCase
     2from django.test.utils import override_settings
     3from django.utils import translation
     4
     5class TranslationTestCase(TestCase):
     6    def setUp(self):
     7        self.language = 'pl'
     8        self.path_slash = '/%s/' % self.language
     9        self.path_no_slash = '/%s' % self.language
     10        self.path_unknown = '/xyz/'
     11
     12
     13@override_settings(USE_I18N = True)
     14class TranslationI18nEnabledTests(TranslationTestCase):
     15    def test_get_language_from_path(self):
     16        self.assertEqual(translation.get_language_from_path(self.path_slash), self.language)
     17        self.assertEqual(translation.get_language_from_path(self.path_no_slash), self.language)
     18        self.assertEqual(translation.get_language_from_path(self.path_unknown), None)
     19       
     20       
     21@override_settings(USE_I18N = False)
     22class TranslationI18nDisabledTests(TranslationTestCase):     
     23    def test_get_language_from_path(self):
     24        self.assertEqual(translation.get_language_from_path(self.path_slash), None)
     25        self.assertEqual(translation.get_language_from_path(self.path_no_slash), None)
     26        self.assertEqual(translation.get_language_from_path(self.path_unknown), None)
     27       
     28 No newline at end of file
Back to Top