Commits

Carl Meyer committed 4f72ed1

Improved test for issue #15.

  • Participants
  • Parent commits 41b305e

Comments (0)

Files changed (3)

File docs/history.rst

 ---------
 
 Tip: (unreleased)
-  * Sorted language codes longest-first to avoid matching e.g. 'nl' before
-    'nl-be'. Fixes #15. Thanks Roman Barczyński for report and draft patch.
+  * Sorted language codes longest-first to avoid matching e.g. 'pt' before
+    'pt-br'. Fixes #15. Thanks Roman Barczyński for report and draft patch.
   * Added ``LOCALE_INDEPENDENT_STATIC_URL`` setting to mirror
     ``LOCALE_INDEPENDENT_MEDIA_URL``. This setting defaults to True, so if you
     want URLs under STATIC_URL to be locale-dependent, you will need to set it

File localeurl/settings.py

 from django.conf import settings
 
 SUPPORTED_LOCALES = dict(settings.LANGUAGES)
-# Sort locale codes longest-first to avoid matching e.g. 'nl' before 'nl-be'
+# Issue #15. Sort locale codes to avoid matching e.g. 'pt' before 'pt-br'
 LOCALES_RE = '|'.join(
     sorted(SUPPORTED_LOCALES.keys(), key=lambda i: len(i), reverse=True))
 PATH_RE = re.compile(r'^/(?P<locale>%s)(?P<path>.*)$' % LOCALES_RE)

File localeurl/tests/__init__.py

         USE_I18N = True,
         LANGUAGES = (
             ('en', 'English'),
-            ('nl', 'Dutch'),
             ('nl-nl', 'Dutch'),
             ('nl-be', 'Flemish'),
             ('fr', 'French'),
+            ('pt', 'Portuguese'),
+            ('pt-br', 'Brazilian Portuguese'),
         ),
         LANGUAGE_CODE = 'en-gb',
         LOCALE_INDEPENDENT_PATHS = (
                 utils.strip_path('/de/about/localeurl/'))
 
 
+    def test_strip_path_takes_longer_code_first(self):
+        # Refs issue #15.
+        self.assertEqual(('pt-br', '/about/localeurl/'),
+                utils.strip_path('/pt-br/about/localeurl/'))
+
+
     def test_supported_language(self):
         self.assertEqual('fr', utils.supported_language('fr'))
         self.assertEqual('nl-be', utils.supported_language('nl-be'))
 
     def test_locale_url_tag(self):
         self.assertRaises(ValueError, self.render_template,
-                '{% locale_url "pt" dummy0 %}')
+                '{% locale_url "nl" dummy0 %}')
 
         self.assertEqual('/en/dummy/', self.render_template(
                 '{% locale_url "en-us" dummy0 %}'))
 
         def test_locale_url_tag(self):
             self.assertRaises(ValueError, self.render_template,
-                    '{% locale_url "pt" "dummy0" %}')
+                    '{% locale_url "nl" "dummy0" %}')
 
             self.assertEqual('/en/dummy/', self.render_template(
                     '{% locale_url "en-us" "dummy0" %}'))