def process_response(self, request, response): if response.status_code != 404: return response # No need to check for a flatpage for non-404 responses. try: return page(request, request.path_info) # Return the original response if any errors happened. Because this # is a middleware, we can't assume the errors will be caught elsewhere. except Http404: return response except: if settings.DEBUG: raise return response
def process_response(self, request, response): if response.status_code != 404: return response # No need to check for a page for non-404 responses. try: return page(request, request.path_info) # Return the original response if any errors happened. Because this # is a middleware, we can't assume the errors will be caught elsewhere. except Http404: return response except: if settings.DEBUG: raise return response
def process_response(self, request, response): if response.status_code != 404: # Pass anything but a 404 straight through. return response try: # Try the page view. return page(request, request.path_info) except Http404: # If the page view 404s, return the ORIGINAL 404 response. return response except: # If anything else happened, something is wrong with the page view. # Return the original (404) response, unless we're in DEBUG. if settings.DEBUG: raise return response
def test_page(self): self.assertEqual(views.page(1), "/apis/v2/page/1") views.page = MagicMock(return_value="/apis/v1/page/1") self.assertEqual(views.page(1), "/apis/v2/page/1") # fails
def test_page(self): res = views.page(1) self.assertEqual(res, "/apis/v1/page/1")