diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 09:53:47 +0100 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 14:36:57 +0100 |
| commit | 89f40e36246100df6a11316c31a76712ebc6c501 (patch) | |
| tree | 6e65639683ddaf2027908d1ecb1739e0e2ff853b /tests/regressiontests/conditional_processing | |
| parent | b3d2ccb5bfbaf6e7fe1f98843baaa48c35a70950 (diff) | |
Merged regressiontests and modeltests into the test root.
Diffstat (limited to 'tests/regressiontests/conditional_processing')
4 files changed, 0 insertions, 171 deletions
diff --git a/tests/regressiontests/conditional_processing/__init__.py b/tests/regressiontests/conditional_processing/__init__.py deleted file mode 100644 index 380474e035..0000000000 --- a/tests/regressiontests/conditional_processing/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# -*- coding:utf-8 -*- diff --git a/tests/regressiontests/conditional_processing/models.py b/tests/regressiontests/conditional_processing/models.py deleted file mode 100644 index b47fdf6fb5..0000000000 --- a/tests/regressiontests/conditional_processing/models.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding:utf-8 -*- -from __future__ import unicode_literals - -from datetime import datetime - -from django.test import TestCase - - -FULL_RESPONSE = 'Test conditional get response' -LAST_MODIFIED = datetime(2007, 10, 21, 23, 21, 47) -LAST_MODIFIED_STR = 'Sun, 21 Oct 2007 23:21:47 GMT' -LAST_MODIFIED_NEWER_STR = 'Mon, 18 Oct 2010 16:56:23 GMT' -LAST_MODIFIED_INVALID_STR = 'Mon, 32 Oct 2010 16:56:23 GMT' -EXPIRED_LAST_MODIFIED_STR = 'Sat, 20 Oct 2007 23:21:47 GMT' -ETAG = 'b4246ffc4f62314ca13147c9d4f76974' -EXPIRED_ETAG = '7fae4cd4b0f81e7d2914700043aa8ed6' - -class ConditionalGet(TestCase): - urls = 'regressiontests.conditional_processing.urls' - - def assertFullResponse(self, response, check_last_modified=True, check_etag=True): - self.assertEqual(response.status_code, 200) - self.assertEqual(response.content, FULL_RESPONSE.encode()) - if check_last_modified: - self.assertEqual(response['Last-Modified'], LAST_MODIFIED_STR) - if check_etag: - self.assertEqual(response['ETag'], '"%s"' % ETAG) - - def assertNotModified(self, response): - self.assertEqual(response.status_code, 304) - self.assertEqual(response.content, b'') - - def testWithoutConditions(self): - response = self.client.get('/condition/') - self.assertFullResponse(response) - - def testIfModifiedSince(self): - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_STR - response = self.client.get('/condition/') - self.assertNotModified(response) - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_NEWER_STR - response = self.client.get('/condition/') - self.assertNotModified(response) - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_INVALID_STR - response = self.client.get('/condition/') - self.assertFullResponse(response) - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = EXPIRED_LAST_MODIFIED_STR - response = self.client.get('/condition/') - self.assertFullResponse(response) - - def testIfNoneMatch(self): - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % ETAG - response = self.client.get('/condition/') - self.assertNotModified(response) - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % EXPIRED_ETAG - response = self.client.get('/condition/') - self.assertFullResponse(response) - - # Several etags in If-None-Match is a bit exotic but why not? - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s", "%s"' % (ETAG, EXPIRED_ETAG) - response = self.client.get('/condition/') - self.assertNotModified(response) - - def testIfMatch(self): - self.client.defaults['HTTP_IF_MATCH'] = '"%s"' % ETAG - response = self.client.put('/condition/etag/') - self.assertEqual(response.status_code, 200) - self.client.defaults['HTTP_IF_MATCH'] = '"%s"' % EXPIRED_ETAG - response = self.client.put('/condition/etag/') - self.assertEqual(response.status_code, 412) - - def testBothHeaders(self): - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_STR - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % ETAG - response = self.client.get('/condition/') - self.assertNotModified(response) - - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = EXPIRED_LAST_MODIFIED_STR - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % ETAG - response = self.client.get('/condition/') - self.assertFullResponse(response) - - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_STR - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % EXPIRED_ETAG - response = self.client.get('/condition/') - self.assertFullResponse(response) - - def testSingleCondition1(self): - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = LAST_MODIFIED_STR - response = self.client.get('/condition/last_modified/') - self.assertNotModified(response) - response = self.client.get('/condition/etag/') - self.assertFullResponse(response, check_last_modified=False) - - def testSingleCondition2(self): - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % ETAG - response = self.client.get('/condition/etag/') - self.assertNotModified(response) - response = self.client.get('/condition/last_modified/') - self.assertFullResponse(response, check_etag=False) - - def testSingleCondition3(self): - self.client.defaults['HTTP_IF_MODIFIED_SINCE'] = EXPIRED_LAST_MODIFIED_STR - response = self.client.get('/condition/last_modified/') - self.assertFullResponse(response, check_etag=False) - - def testSingleCondition4(self): - self.client.defaults['HTTP_IF_NONE_MATCH'] = '"%s"' % EXPIRED_ETAG - 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) - - def testInvalidETag(self): - self.client.defaults['HTTP_IF_NONE_MATCH'] = r'"\"' - response = self.client.get('/condition/etag/') - self.assertFullResponse(response, check_last_modified=False) diff --git a/tests/regressiontests/conditional_processing/urls.py b/tests/regressiontests/conditional_processing/urls.py deleted file mode 100644 index 1ed7b1264a..0000000000 --- a/tests/regressiontests/conditional_processing/urls.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.conf.urls import patterns - -from . import views - - -urlpatterns = patterns('', - ('^condition/$', views.index), - ('^condition/last_modified/$', views.last_modified_view1), - ('^condition/last_modified2/$', views.last_modified_view2), - ('^condition/etag/$', views.etag_view1), - ('^condition/etag2/$', views.etag_view2), -) diff --git a/tests/regressiontests/conditional_processing/views.py b/tests/regressiontests/conditional_processing/views.py deleted file mode 100644 index 2188c9b462..0000000000 --- a/tests/regressiontests/conditional_processing/views.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding:utf-8 -*- -from __future__ import absolute_import - -from django.views.decorators.http import condition, etag, last_modified -from django.http import HttpResponse - -from .models import FULL_RESPONSE, LAST_MODIFIED, ETAG - - -def index(request): - return HttpResponse(FULL_RESPONSE) -index = condition(lambda r: ETAG, lambda r: LAST_MODIFIED)(index) - -def last_modified_view1(request): - return HttpResponse(FULL_RESPONSE) -last_modified_view1 = condition(last_modified_func=lambda r: LAST_MODIFIED)(last_modified_view1) - -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) - |
