summaryrefslogtreecommitdiff
path: root/tests/regressiontests/conditional_processing
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-24 03:01:46 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-24 03:01:46 +0000
commite5a8d9e810a00898345e15f1af5c4099e746c7a0 (patch)
tree0a824452fa695eff14ec5ec5739716525d048f64 /tests/regressiontests/conditional_processing
parent2fb7f5ea2b488ec9b97e1cc1f8e1554d681c6f9b (diff)
A bunch of improvements for conditional HTTP processing.
Fixed some typos in the code (fixed #10586). Added more tests. Made the tests compatible with Python 2.3. Improved the documentation by putting the good news and common use-case right up front. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10134 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/conditional_processing')
-rw-r--r--tests/regressiontests/conditional_processing/models.py15
-rw-r--r--tests/regressiontests/conditional_processing/urls.py6
-rw-r--r--tests/regressiontests/conditional_processing/views.py21
3 files changed, 34 insertions, 8 deletions
diff --git a/tests/regressiontests/conditional_processing/models.py b/tests/regressiontests/conditional_processing/models.py
index 120a673859..756244ab3b 100644
--- a/tests/regressiontests/conditional_processing/models.py
+++ b/tests/regressiontests/conditional_processing/models.py
@@ -98,6 +98,21 @@ class ConditionalGet(TestCase):
response = self.client.get('/condition/etag/')
self.assertFullResponse(response, check_last_modified=False)
+ def testSingleCondition5(self):
+ self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_STR
+ response = self.client.get('/condition/last_modified2/')
+ self.assertNotModified(response)
+ response = self.client.get('/condition/etag2/')
+ self.assertFullResponse(response, check_last_modified=False)
+
+ def testSingleCondition6(self):
+ self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % ETAG
+ response = self.client.get('/condition/etag2/')
+ self.assertNotModified(response)
+ response = self.client.get('/condition/last_modified2/')
+ self.assertFullResponse(response, check_etag=False)
+
+
class ETagProcesing(TestCase):
def testParsing(self):
etags = parse_etags(r'"", "etag", "e\"t\"ag", "e\\tag", W/"weak"')
diff --git a/tests/regressiontests/conditional_processing/urls.py b/tests/regressiontests/conditional_processing/urls.py
index 938a4e4833..4dbe11a230 100644
--- a/tests/regressiontests/conditional_processing/urls.py
+++ b/tests/regressiontests/conditional_processing/urls.py
@@ -3,6 +3,8 @@ import views
urlpatterns = patterns('',
('^$', views.index),
- ('^last_modified/$', views.last_modified),
- ('^etag/$', views.etag),
+ ('^last_modified/$', views.last_modified_view1),
+ ('^last_modified2/$', views.last_modified_view2),
+ ('^etag/$', views.etag_view1),
+ ('^etag2/$', views.etag_view2),
)
diff --git a/tests/regressiontests/conditional_processing/views.py b/tests/regressiontests/conditional_processing/views.py
index c88236e21b..df4928133d 100644
--- a/tests/regressiontests/conditional_processing/views.py
+++ b/tests/regressiontests/conditional_processing/views.py
@@ -1,17 +1,26 @@
# -*- coding:utf-8 -*-
-from django.views.decorators.http import condition
+from django.views.decorators.http import condition, etag, last_modified
from django.http import HttpResponse
from models import FULL_RESPONSE, LAST_MODIFIED, ETAG
-@condition(lambda r: ETAG, lambda r: LAST_MODIFIED)
def index(request):
return HttpResponse(FULL_RESPONSE)
+index = condition(lambda r: ETAG, lambda r: LAST_MODIFIED)(index)
-@condition(last_modified_func=lambda r: LAST_MODIFIED)
-def last_modified(request):
+def last_modified_view1(request):
return HttpResponse(FULL_RESPONSE)
+last_modified_view1 = condition(last_modified_func=lambda r: LAST_MODIFIED)(last_modified_view1)
-@condition(etag_func=lambda r: ETAG)
-def etag(request):
+def last_modified_view2(request):
return HttpResponse(FULL_RESPONSE)
+last_modified_view2 = last_modified(lambda r: LAST_MODIFIED)(last_modified_view2)
+
+def etag_view1(request):
+ return HttpResponse(FULL_RESPONSE)
+etag_view1 = condition(etag_func=lambda r: ETAG)(etag_view1)
+
+def etag_view2(request):
+ return HttpResponse(FULL_RESPONSE)
+etag_view2 = etag(lambda r: ETAG)(etag_view2)
+