def test_render_roughpage(self, RequestContext, HttpResponse): t = MagicMock() r = render_roughpage(self.request, t) # RequestContext should be initialized with request RequestContext.assert_called_with(self.request) # t.render should be called with the context t.render.assert_called_with(RequestContext()) # HttpResponse should be initialized with the output of # t.render(c) HttpResponse.assert_called_with(t.render(RequestContext())) # return should be response self.assertEqual(r, HttpResponse())
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 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_render_roughpage(self, RequestContext, HttpResponse): t = MagicMock() r = render_roughpage(self.request, t) import django if django.VERSION >= (1, 8): # Newer than 1.8, template.render should be passed dict and Request instead of RequestContext as arguments t.render_assert_called_with({}, self.request) HttpResponse.assert_called_with(t.render({}, self.request)) self.assertEqual(r, HttpResponse()) else: # RequestContext should be initialized with request RequestContext.assert_called_with(self.request) # t.render should be called with the context t.render.assert_called_with(RequestContext()) # HttpResponse should be initialized with the output of # t.render(c) HttpResponse.assert_called_with(t.render(RequestContext())) # return should be response self.assertEqual(r, HttpResponse())