From 7b9cb41a091119d23a1226f1f612649b2d64709d Mon Sep 17 00:00:00 2001
From: Mike Lundy <mike@fluffypenguin.org>
Date: Sun, 22 Mar 2009 18:02:18 -0500
Subject: [PATCH] pass render_to_response status param through to HttpResponse
---
django/shortcuts/__init__.py | 2 +-
.../regressiontests/test_client_regress/models.py | 7 +++++++
tests/regressiontests/test_client_regress/urls.py | 1 +
tests/regressiontests/test_client_regress/views.py | 4 ++++
4 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/django/shortcuts/__init__.py b/django/shortcuts/__init__.py
index 1cece7c..ffd30e8 100644
a
|
b
|
def render_to_response(*args, **kwargs):
|
14 | 14 | Returns a HttpResponse whose content is filled with the result of calling |
15 | 15 | django.template.loader.render_to_string() with the passed arguments. |
16 | 16 | """ |
17 | | httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)} |
| 17 | httpresponse_kwargs = dict([(k, kwargs.pop(k, None)) for k in ('mimetype', 'status')]) |
18 | 18 | return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) |
19 | 19 | |
20 | 20 | def _get_queryset(klass): |
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index 5d65092..d225bdd 100644
a
|
b
|
class QueryStringTests(TestCase):
|
594 | 594 | self.assertEqual(response.context['post-bar'], 'bang') |
595 | 595 | self.assertEqual(response.context['request-foo'], 'whiz') |
596 | 596 | self.assertEqual(response.context['request-bar'], 'bang') |
| 597 | |
| 598 | def test_get_error_requests(self): |
| 599 | response = self.client.get("/test_client_regress/request_error/", data={'status': 200}) |
| 600 | self.assertEqual(response.status_code, 200) |
| 601 | |
| 602 | response = self.client.get("/test_client_regress/request_error/", data={'status': 404}) |
| 603 | self.assertEqual(response.status_code, 404) |
diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
index 0f9082d..f68ed03 100644
a
|
b
|
urlpatterns = patterns('',
|
8 | 8 | (r'^get_view/$', views.get_view), |
9 | 9 | (r'^request_data/$', views.request_data), |
10 | 10 | (r'^request_data_extended/$', views.request_data, {'template':'extended.html', 'data':'bacon'}), |
| 11 | (r'^request_error/$', views.request_error), |
11 | 12 | url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), |
12 | 13 | (r'^login_protected_redirect_view/$', views.login_protected_redirect_view), |
13 | 14 | (r'^redirects/$', redirect_to, {'url': '/test_client_regress/redirects/further/'}), |
diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
index bd0b8af..ede7029 100644
a
|
b
|
def request_data(request, template='base.html', data='sausage'):
|
31 | 31 | 'data': data, |
32 | 32 | }) |
33 | 33 | |
| 34 | def request_error(request, template='base.html'): |
| 35 | "A simple view that returns the given status code" |
| 36 | return render_to_response(template, {}, status=int(request.REQUEST.get('status', 200))) |
| 37 | |
34 | 38 | def view_with_argument(request, name): |
35 | 39 | """A view that takes a string argument |
36 | 40 | |