def test_410_gone(self):
     path = '/bar/'
     redirects = (
             {'source': '/bar/', 'target': None, 'status_code': None, 'filename': '', 'line_number':1},
         )
     response = get_redirect(preprocess_redirects(redirects), path, '')
     self.assertEqual(response.status_code, 410)
Пример #2
0
 def test_410_gone(self):
     path = '/bar/'
     redirects = ({
         'source': '/bar/',
         'target': None,
         'status_code': None,
         'filename': '',
         'line_number': 1
     }, )
     response = get_redirect(preprocess_redirects(redirects), path, '')
     self.assertEqual(response.status_code, 410)
Пример #3
0
    def process_response(self, request, response):
        is_404 = response.status_code == 404
        is_my_site = get_current_site(request).domain == request.get_host()

        # Mezzanine has a urlpattern for all urls that end in a slash, so
        # CommonMiddleware redirects all 404s. We still need to check for a
        # redirect in this case.
        is_common_redirect = False
        if settings.APPEND_SLASH and response.status_code == 301:
            parsed = urlparse(response['Location'])
            if parsed.path == request.path_info + '/':
                is_common_redirect = True

        if (is_404 or not is_my_site) or is_common_redirect:
            path = request.get_full_path()
            full_uri = request.build_absolute_uri()
            response = get_redirect(self.redirects, path, full_uri) or response
        return response
Пример #4
0
    def process_response(self, request, response):
        is_404 = response.status_code == 404
        is_my_site = get_current_site(request).domain == request.get_host()

        # Mezzanine has a urlpattern for all urls that end in a slash, so
        # CommonMiddleware redirects all 404s. We still need to check for a
        # redirect in this case.
        is_common_redirect = False
        if settings.APPEND_SLASH and response.status_code == 301:
            parsed = urlparse(response['Location'])
            if parsed.path == request.path_info + '/':
                is_common_redirect = True

        if (is_404 or not is_my_site) or is_common_redirect:
            path = request.get_full_path()
            full_uri = request.build_absolute_uri()
            response = get_redirect(self.redirects, path, full_uri) or response
        return response
Пример #5
0
 def test_303_redirect(self):
     path = '/foo/303/'
     response = get_redirect(self.redirects, path, '')
     self.assertEqual(response['Location'], '/bar/')
     self.assertEqual(response.status_code, 303)
Пример #6
0
 def test_basic_redirect_with_domain(self):
     path = '/asdf/'
     full_path = 'http://www.fusionbox.com/asdf/'
     response = get_redirect(self.redirects, path, full_path)
     self.assertEqual(response['Location'], '/foo/bar/')
     self.assertEqual(response.status_code, 301)
 def test_303_redirect(self):
     path = '/foo/303/'
     response = get_redirect(self.redirects, path, '')
     self.assertEqual(response['Location'], '/bar/')
     self.assertEqual(response.status_code, 303)
 def test_basic_redirect_with_domain(self):
     path = '/asdf/'
     full_path = 'http://www.fusionbox.com/asdf/'
     response = get_redirect(self.redirects, path, full_path)
     self.assertEqual(response['Location'], '/foo/bar/')
     self.assertEqual(response.status_code, 301)