Fixed #31459 -- Fixed handling invalid indentifiers in URL path conversion.

This patch adjusted existing tests that used invalid identifiers.
This commit is contained in:
Adam Johnson 2020-04-13 09:07:28 +01:00 committed by Mariusz Felisiak
parent 578c03b276
commit 4bb33bb074
5 changed files with 13 additions and 5 deletions

View file

@ -249,7 +249,7 @@ class SameNameTests(SimpleTestCase):
class ParameterRestrictionTests(SimpleTestCase):
def test_non_identifier_parameter_name_causes_exception(self):
def test_integer_parameter_name_causes_exception(self):
msg = (
"URL route 'hello/<int:1>/' uses parameter name '1' which isn't "
"a valid Python identifier."
@ -257,6 +257,14 @@ class ParameterRestrictionTests(SimpleTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
path(r'hello/<int:1>/', lambda r: None)
def test_non_identifier_parameter_name_causes_exception(self):
msg = (
"URL route 'b/<int:book.id>/' uses parameter name 'book.id' which "
"isn't a valid Python identifier."
)
with self.assertRaisesMessage(ImproperlyConfigured, msg):
path(r'b/<int:book.id>/', lambda r: None)
def test_allows_non_ascii_but_valid_identifiers(self):
# \u0394 is "GREEK CAPITAL LETTER DELTA", a valid identifier.
p = path('hello/<str:\u0394>/', lambda r: None)