From 34d5336b9deed41c6b61989f8cd755e9d179ce4c Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 2 Aug 2021 11:36:25 +0200 Subject: [PATCH] Added test for TemplateSyntaxError when variables begin with underscores. --- tests/template_tests/test_parser.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py index 6c8b70d16f..23d8795d7f 100644 --- a/tests/template_tests/test_parser.py +++ b/tests/template_tests/test_parser.py @@ -79,11 +79,12 @@ class ParserTests(SimpleTestCase): Variable(r"'Some \'Better\' News'").resolve(c), "Some 'Better' News" ) - # Variables should reject access of attributes beginning with - # underscores. - msg = "Variables and attributes may not begin with underscores: 'article._hidden'" - with self.assertRaisesMessage(TemplateSyntaxError, msg): - Variable("article._hidden") + # Variables should reject access of attributes and variables beginning + # with underscores. + for name in ['article._hidden', '_article']: + msg = f"Variables and attributes may not begin with underscores: '{name}'" + with self.assertRaisesMessage(TemplateSyntaxError, msg): + Variable(name) # Variables should raise on non string type with self.assertRaisesMessage(TypeError, "Variable must be a string or number, got "):