1
0
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:
Alokik Vijay
2022-03-28 21:26:20 +05:30
committed by Mariusz Felisiak
parent 83c803f161
commit baf9604ed8
11 changed files with 163 additions and 14 deletions

View File

@@ -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):
"""

View File

@@ -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",
),
]