def test_roughpage_index(self, loader, render_roughpage): url = '/' r = roughpage(self.request, url) # loader.select_template should be called with follow # because backend is PlainTemplateFilenameBackend template_filenames = ['roughpages/index.html'] loader.select_template.assert_called_with(template_filenames) # render_roughpage should be called with t = loader.select_template() render_roughpage.assert_called_with(self.request, t) # should return the return of render_roughpage self.assertEqual(r, render_roughpage())
def process_response(self, request, response): if response.status_code != 404: # Non 404 response should not be treated with this middleware return response try: return roughpage(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 Exception: if settings.DEBUG: raise return response
def test_roughpage_index_auth(self, get_backend, loader, render_roughpage): from roughpages.backends import AuthTemplateFilenameBackend get_backend.return_value = AuthTemplateFilenameBackend() url = '/' r = roughpage(self.request, url) # loader.select_template should be called with follow # because backend is PlainTemplateFilenameBackend template_filenames = [ 'roughpages/index.anonymous.html', 'roughpages/index.html', ] loader.select_template.assert_called_with(template_filenames) # render_roughpage should be called with t = loader.select_template() render_roughpage.assert_called_with(self.request, t) # should return the return of render_roughpage self.assertEqual(r, render_roughpage())
def test_roughpage_redirect(self, redirect): url = '/foo/bar/hoge' roughpage(self.request, url) # redirect should be called redirect.assert_called_with(url + '/', permanent=True)