Exemple #1
0
 def test_ending_with_dollar(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, '2_0.W001')
     expected_msg = "Your URL pattern 'ending-with-dollar$' has a route"
     self.assertIn(expected_msg, warning.msg)
Exemple #2
0
 def test_name_with_colon(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W003')
     expected_msg = "Your URL pattern '^$' [name='name_with:colon'] has a name including a ':'."
     self.assertIn(expected_msg, warning.msg)
Exemple #3
0
 def test_beginning_with_caret(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, '2_0.W001')
     expected_msg = "Your URL pattern '^beginning-with-caret' has a route"
     self.assertIn(expected_msg, warning.msg)
Exemple #4
0
 def test_contains_re_named_group(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, '2_0.W001')
     expected_msg = "Your URL pattern '(?P<named-group>\\d+)' has a route"
     self.assertIn(expected_msg, warning.msg)
Exemple #5
0
 def test_contains_included_tuple(self):
     result = check_url_config(None)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.E004')
     self.assertRegex(warning.msg, (
         r"^Your URL pattern \('\^tuple/\$', <function <lambda> at 0x(\w+)>\) is "
         r"invalid. Ensure that urlpatterns is a list of path\(\) and/or re_path\(\) "
         r"instances\.$"
     ))
Exemple #6
0
 def test_include_with_dollar(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W001')
     self.assertEqual(warning.msg, (
         "Your URL pattern '^include-with-dollar$' uses include with a "
         "route ending with a '$'. Remove the dollar from the route to "
         "avoid problems including URLs."
     ))
Exemple #7
0
 def test_beginning_with_slash(self):
     msg = (
         "Your URL pattern '%s' has a route beginning with a '/'. Remove "
         "this slash as it is unnecessary. If this pattern is targeted in "
         "an include(), ensure the include() pattern has a trailing '/'."
     )
     warning1, warning2 = check_url_config(None)
     self.assertEqual(warning1.id, 'urls.W002')
     self.assertEqual(warning1.msg, msg % '/path-starting-with-slash/')
     self.assertEqual(warning2.id, 'urls.W002')
     self.assertEqual(warning2.msg, msg % '/url-starting-with-slash/$')
Exemple #8
0
 def test_no_root_urlconf_in_settings(self):
     delattr(settings, 'ROOT_URLCONF')
     result = check_url_config(None)
     self.assertEqual(result, [])
Exemple #9
0
 def test_beginning_with_slash_append_slash(self):
     # It can be useful to start a URL pattern with a slash when
     # APPEND_SLASH=False (#27238).
     result = check_url_config(None)
     self.assertEqual(result, [])
Exemple #10
0
 def test_check_resolver_recursive(self):
     # The resolver is checked recursively (examining url()s in include()).
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W001')
Exemple #11
0
 def test_no_warnings_i18n(self):
     self.assertEqual(check_url_config(None), [])
Exemple #12
0
 def test_no_warnings(self):
     result = check_url_config(None)
     self.assertEqual(result, [])