Пример #1
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)
Пример #2
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)
Пример #3
0
 def test_beginning_with_slash(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W002')
     expected_msg = "Your URL pattern '/starting-with-slash/$' has a regex beginning with a '/'"
     self.assertIn(expected_msg, warning.msg)
Пример #4
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')
     expected_msg = "Your URL pattern '^include-with-dollar$' uses include with a regex ending with a '$'."
     self.assertIn(expected_msg, warning.msg)
Пример #5
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)
Пример #6
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)
Пример #7
0
 def test_contains_tuple_not_url_instance(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 url\(\) instances.$"
     ))
Пример #8
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."
     ))
Пример #9
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/$')
Пример #10
0
 def test_bad_handlers(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 4)
     for code, num_params, error in zip([400, 403, 404, 500], [2, 2, 2, 1], result):
         with self.subTest('handler{}'.format(code)):
             self.assertEqual(error, Error(
                 "The custom handler{} view "
                 "'check_framework.urls.bad_error_handlers.bad_handler' "
                 "does not take the correct number of arguments (request{})."
                 .format(code, ', exception' if num_params == 2 else ''),
                 id='urls.E007',
             ))
Пример #11
0
    def test_beginning_with_slash(self):
        result = check_url_config(None)
        self.assertEqual(len(result), 1)
        warning = result[0]
        self.assertEqual(warning.id, 'urls.W002')
        expected_msg = (
            "Your URL pattern '/starting-with-slash/$' has a regex 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 '/'."
        )

        self.assertIn(expected_msg, warning.msg)
Пример #12
0
 def test_bad_handlers_invalid_path(self):
     result = check_url_config(None)
     paths = [
         'django.views.bad_handler',
         'django.invalid_module.bad_handler',
         'invalid_module.bad_handler',
         'django',
     ]
     hints = [
         "Could not import '{}'. View does not exist in module django.views.",
         "Could not import '{}'. Parent module django.invalid_module does not exist.",
         "No module named 'invalid_module'",
         "Could not import '{}'. The path must be fully qualified.",
     ]
     for code, path, hint, error in zip([400, 403, 404, 500], paths, hints, result):
         with self.subTest('handler{}'.format(code)):
             self.assertEqual(error, Error(
                 "The custom handler{} view '{}' could not be imported.".format(code, path),
                 hint=hint.format(path),
                 id='urls.E008',
             ))
Пример #13
0
 def test_no_root_urlconf_in_settings(self):
     delattr(settings, 'ROOT_URLCONF')
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #14
0
 def test_check_resolver_recursive(self):
     # The resolver is checked recursively (examining URL patterns in include()).
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W001')
Пример #15
0
 def test_good_handlers(self):
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #16
0
 def test_no_warnings_i18n(self):
     self.assertEqual(check_url_config(None), [])
Пример #17
0
 def test_good_handlers(self):
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #18
0
 def test_no_warnings_i18n(self):
     self.assertEqual(check_url_config(None), [])
Пример #19
0
 def test_no_warnings(self):
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #20
0
 def test_check_resolver_recursive(self):
     # The resolver is checked recursively (examining URL patterns in include()).
     result = check_url_config(None)
     self.assertEqual(len(result), 1)
     warning = result[0]
     self.assertEqual(warning.id, 'urls.W001')
Пример #21
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, [])
Пример #22
0
 def test_no_warnings(self):
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #23
0
 def test_no_root_urlconf_in_settings(self):
     delattr(settings, 'ROOT_URLCONF')
     result = check_url_config(None)
     self.assertEqual(result, [])
Пример #24
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, [])