Ticket #17555: 17555.v2.diff

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

Update tests to avoid using override_settings

  • 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..d86ed1f
    - +  
     1from django.test import TestCase
     2from django.utils.translation.trans_real import get_language_from_path as get_language_from_path_real
     3from django.utils.translation.trans_null import get_language_from_path as get_language_from_path_null
     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
     13class TranslationI18nEnabledTests(TranslationTestCase):
     14    def test_get_language_from_path(self):
     15        self.assertEqual(get_language_from_path_real(self.path_slash), self.language)
     16        self.assertEqual(get_language_from_path_real(self.path_no_slash), self.language)
     17        self.assertEqual(get_language_from_path_real(self.path_unknown), None)
     18
     19
     20class TranslationI18nDisabledTests(TranslationTestCase):
     21    def test_get_language_from_path(self):
     22        self.assertEqual(get_language_from_path_null(self.path_slash), None)
     23        self.assertEqual(get_language_from_path_null(self.path_no_slash), None)
     24        self.assertEqual(get_language_from_path_null(self.path_unknown), None)
     25
Back to Top