mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #16406 -- Added ResolveMatch.captured_kwargs and extra_kwargs.
Thanks Florian Apolloner for the review and implementation idea.
This commit is contained in:
committed by
Mariusz Felisiak
parent
83c803f161
commit
baf9604ed8
@@ -8,7 +8,7 @@ from django.template import Context, Template
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_script_prefix
|
||||
from django.urls import clear_url_caches, reverse, translate_url
|
||||
from django.urls import clear_url_caches, resolve, reverse, translate_url
|
||||
from django.utils import translation
|
||||
|
||||
|
||||
@@ -198,6 +198,23 @@ class URLTranslationTests(URLTestCaseBase):
|
||||
self.assertEqual(translate_url("/nl/gebruikers/", "en"), "/en/users/")
|
||||
self.assertEqual(translation.get_language(), "nl")
|
||||
|
||||
def test_reverse_translated_with_captured_kwargs(self):
|
||||
with translation.override("en"):
|
||||
match = resolve("/translated/apo/")
|
||||
# Links to the same page in other languages.
|
||||
tests = [
|
||||
("nl", "/vertaald/apo/"),
|
||||
("pt-br", "/traduzidos/apo/"),
|
||||
]
|
||||
for lang, expected_link in tests:
|
||||
with translation.override(lang):
|
||||
self.assertEqual(
|
||||
reverse(
|
||||
match.url_name, args=match.args, kwargs=match.captured_kwargs
|
||||
),
|
||||
expected_link,
|
||||
)
|
||||
|
||||
|
||||
class URLNamespaceTests(URLTestCaseBase):
|
||||
"""
|
||||
|
||||
@@ -10,7 +10,10 @@ urlpatterns = [
|
||||
path("not-prefixed-include/", include("i18n.patterns.urls.included")),
|
||||
re_path(_(r"^translated/$"), view, name="no-prefix-translated"),
|
||||
re_path(
|
||||
_(r"^translated/(?P<slug>[\w-]+)/$"), view, name="no-prefix-translated-slug"
|
||||
_(r"^translated/(?P<slug>[\w-]+)/$"),
|
||||
view,
|
||||
{"slug": "default-slug"},
|
||||
name="no-prefix-translated-slug",
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user