44
55from django .conf import settings
66from django .conf .urls import url
7-
7+ from django . conf . urls . i18n import i18n_patterns
88from django .http import HttpResponse
9+ from django .urls import path
910
10- from multiurl import multiurl , ContinueResolving
11+ from multiurl import ContinueResolving , multiurl
1112
1213try :
1314 from django import urls as urlresolvers
@@ -33,6 +34,14 @@ def setUp(self):
3334 )
3435 ])
3536
37+ self .patterns_pathall = urlresolvers .URLResolver (RegexPattern (r'^/' ), i18n_patterns (
38+ multiurl (
39+ path ('<str:name>/' , brand , name = 'brand' ),
40+ path ('<str:name>/' , model , name = 'model' ),
41+ ),
42+ ))
43+
44+
3645 # Patterns with no "catch all" - last view could still raise ContinueResolving.
3746 self .patterns_no_fallthrough = urlresolvers .URLResolver (RegexPattern (r'^/' ), [
3847 multiurl (
@@ -56,6 +65,16 @@ def test_resolve_match_last(self):
5665 response = m .func (request = None , * m .args , ** m .kwargs )
5766 self .assertEqual (response .content , b"Thing: Bacon" )
5867
68+ def test_resolve_match_path_brand (self ):
69+ m = self .patterns_pathall .resolve ('/en-us/bmw/' )
70+ response = m .func (request = None , * m .args , ** m .kwargs )
71+ self .assertEqual (response .content , b"Brand: BMW Series" )
72+
73+ def test_resolve_match_path_model (self ):
74+ m = self .patterns_pathall .resolve ('/en-us/x5/' )
75+ response = m .func (request = None , * m .args , ** m .kwargs )
76+ self .assertEqual (response .content , b"Model: X5 2019" )
77+
5978 def test_resolve_match_faillthrough (self ):
6079 m = self .patterns_no_fallthrough .resolve ('/bacon/' )
6180 with self .assertRaises (urlresolvers .Resolver404 ):
@@ -103,6 +122,24 @@ def thing(request, name):
103122 return HttpResponse ("Thing: " + name .title ())
104123
105124
125+ def brand (request , name ):
126+ brand = {
127+ 'bmw' : 'BMW Series' ,
128+ }
129+ if name in brand :
130+ return HttpResponse ("Brand: " + brand [name ])
131+ raise ContinueResolving
132+
133+
134+ def model (request , name ):
135+ model = {
136+ 'x5' : 'X5 2019' ,
137+ }
138+ if name in model :
139+ return HttpResponse ("Model: " + model [name ])
140+ raise ContinueResolving
141+
142+
106143if __name__ == '__main__' :
107144 settings .configure ()
108145 unittest .main ()
0 commit comments