2007-12-02 23:25:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-05-05 20:49:26 +00:00
|
|
|
import re
|
|
|
|
|
2010-12-04 07:28:12 +00:00
|
|
|
from django.conf import settings
|
2011-05-05 20:49:26 +00:00
|
|
|
from django.core import mail
|
2007-12-02 23:25:55 +00:00
|
|
|
from django.http import HttpRequest
|
|
|
|
from django.middleware.common import CommonMiddleware
|
2011-03-01 14:28:06 +00:00
|
|
|
from django.middleware.http import ConditionalGetMiddleware
|
2010-12-04 07:28:12 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
class CommonMiddlewareTest(TestCase):
|
2008-10-08 08:36:41 +00:00
|
|
|
def setUp(self):
|
2011-05-05 20:49:26 +00:00
|
|
|
self.append_slash = settings.APPEND_SLASH
|
|
|
|
self.prepend_www = settings.PREPEND_WWW
|
|
|
|
self.ignorable_404_urls = settings.IGNORABLE_404_URLS
|
|
|
|
self.send_broken_email_links = settings.SEND_BROKEN_LINK_EMAILS
|
2008-10-08 08:36:41 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2011-05-05 20:49:26 +00:00
|
|
|
settings.APPEND_SLASH = self.append_slash
|
|
|
|
settings.PREPEND_WWW = self.prepend_www
|
|
|
|
settings.IGNORABLE_404_URLS = self.ignorable_404_urls
|
|
|
|
settings.SEND_BROKEN_LINK_EMAILS = self.send_broken_email_links
|
2008-10-08 08:36:41 +00:00
|
|
|
|
2007-12-02 23:25:55 +00:00
|
|
|
def _get_request(self, path):
|
|
|
|
request = HttpRequest()
|
|
|
|
request.META = {
|
|
|
|
'SERVER_NAME': 'testserver',
|
|
|
|
'SERVER_PORT': 80,
|
|
|
|
}
|
2008-08-21 01:32:18 +00:00
|
|
|
request.path = request.path_info = "/middleware/%s" % path
|
2007-12-02 23:25:55 +00:00
|
|
|
return request
|
|
|
|
|
|
|
|
def test_append_slash_have_slash(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that URLs with slashes go unmolested.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('slash/')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_slashless_resource(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that matches to explicit slashless URLs go unmolested.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('noslash')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_slashless_unknown(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that APPEND_SLASH doesn't redirect to unknown resources.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('unknown')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_redirect(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('slash')
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'], 'http://testserver/middleware/slash/')
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_no_redirect_on_POST_in_DEBUG(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that while in debug mode, an exception is raised with a warning
|
|
|
|
when a failed attempt is made to POST to an URL which would normally be
|
|
|
|
redirected to a slashed version.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
settings.DEBUG = True
|
|
|
|
request = self._get_request('slash')
|
|
|
|
request.method = 'POST'
|
|
|
|
self.assertRaises(
|
|
|
|
RuntimeError,
|
|
|
|
CommonMiddleware().process_request,
|
|
|
|
request)
|
|
|
|
try:
|
|
|
|
CommonMiddleware().process_request(request)
|
|
|
|
except RuntimeError, e:
|
2010-12-04 07:28:12 +00:00
|
|
|
self.assertTrue('end in a slash' in str(e))
|
2008-01-03 02:14:29 +00:00
|
|
|
settings.DEBUG = False
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_disabled(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests disabling append slash functionality.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = False
|
|
|
|
request = self._get_request('slash')
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2007-12-02 23:25:55 +00:00
|
|
|
|
|
|
|
def test_append_slash_quoted(self):
|
|
|
|
"""
|
2008-01-03 02:14:29 +00:00
|
|
|
Tests that URLs which require quoting are redirected to their slash
|
|
|
|
version ok.
|
2007-12-02 23:25:55 +00:00
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('needsquoting#')
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(
|
2007-12-02 23:25:55 +00:00
|
|
|
r['Location'],
|
|
|
|
'http://testserver/middleware/needsquoting%23/')
|
2008-10-07 08:22:50 +00:00
|
|
|
|
|
|
|
def test_prepend_www(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = False
|
|
|
|
request = self._get_request('path/')
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(
|
2008-10-07 08:22:50 +00:00
|
|
|
r['Location'],
|
|
|
|
'http://www.testserver/middleware/path/')
|
|
|
|
|
|
|
|
def test_prepend_www_append_slash_have_slash(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('slash/')
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'],
|
2008-10-07 08:22:50 +00:00
|
|
|
'http://www.testserver/middleware/slash/')
|
|
|
|
|
|
|
|
def test_prepend_www_append_slash_slashless(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('slash')
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'],
|
2008-10-07 08:22:50 +00:00
|
|
|
'http://www.testserver/middleware/slash/')
|
2010-12-04 07:28:12 +00:00
|
|
|
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
# The following tests examine expected behavior given a custom urlconf that
|
|
|
|
# overrides the default one through the request object.
|
|
|
|
|
|
|
|
def test_append_slash_have_slash_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that URLs with slashes go unmolested.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/slash/')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
def test_append_slash_slashless_resource_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that matches to explicit slashless URLs go unmolested.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/noslash')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
def test_append_slash_slashless_unknown_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that APPEND_SLASH doesn't redirect to unknown resources.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/unknown')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
def test_append_slash_redirect_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/slash')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2010-12-04 07:28:12 +00:00
|
|
|
self.assertFalse(r is None,
|
2010-03-07 20:03:04 +00:00
|
|
|
"CommonMiddlware failed to return APPEND_SLASH redirect using request.urlconf")
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'], 'http://testserver/middleware/customurlconf/slash/')
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
def test_append_slash_no_redirect_on_POST_in_DEBUG_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that while in debug mode, an exception is raised with a warning
|
|
|
|
when a failed attempt is made to POST to an URL which would normally be
|
|
|
|
redirected to a slashed version.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
settings.DEBUG = True
|
|
|
|
request = self._get_request('customurlconf/slash')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
request.method = 'POST'
|
|
|
|
self.assertRaises(
|
|
|
|
RuntimeError,
|
|
|
|
CommonMiddleware().process_request,
|
|
|
|
request)
|
|
|
|
try:
|
|
|
|
CommonMiddleware().process_request(request)
|
|
|
|
except RuntimeError, e:
|
2010-12-04 07:28:12 +00:00
|
|
|
self.assertTrue('end in a slash' in str(e))
|
2010-03-07 20:03:04 +00:00
|
|
|
settings.DEBUG = False
|
|
|
|
|
|
|
|
def test_append_slash_disabled_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests disabling append slash functionality.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = False
|
|
|
|
request = self._get_request('customurlconf/slash')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(CommonMiddleware().process_request(request), None)
|
2010-03-07 20:03:04 +00:00
|
|
|
|
|
|
|
def test_append_slash_quoted_custom_urlconf(self):
|
|
|
|
"""
|
|
|
|
Tests that URLs which require quoting are redirected to their slash
|
|
|
|
version ok.
|
|
|
|
"""
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/needsquoting#')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2010-12-04 07:28:12 +00:00
|
|
|
self.assertFalse(r is None,
|
2010-03-07 20:03:04 +00:00
|
|
|
"CommonMiddlware failed to return APPEND_SLASH redirect using request.urlconf")
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(
|
2010-03-07 20:03:04 +00:00
|
|
|
r['Location'],
|
|
|
|
'http://testserver/middleware/customurlconf/needsquoting%23/')
|
|
|
|
|
|
|
|
def test_prepend_www_custom_urlconf(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = False
|
|
|
|
request = self._get_request('customurlconf/path/')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(
|
2010-03-07 20:03:04 +00:00
|
|
|
r['Location'],
|
|
|
|
'http://www.testserver/middleware/customurlconf/path/')
|
|
|
|
|
|
|
|
def test_prepend_www_append_slash_have_slash_custom_urlconf(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/slash/')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'],
|
2010-03-07 20:03:04 +00:00
|
|
|
'http://www.testserver/middleware/customurlconf/slash/')
|
|
|
|
|
|
|
|
def test_prepend_www_append_slash_slashless_custom_urlconf(self):
|
|
|
|
settings.PREPEND_WWW = True
|
|
|
|
settings.APPEND_SLASH = True
|
|
|
|
request = self._get_request('customurlconf/slash')
|
|
|
|
request.urlconf = 'regressiontests.middleware.extra_urls'
|
|
|
|
r = CommonMiddleware().process_request(request)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(r.status_code, 301)
|
|
|
|
self.assertEqual(r['Location'],
|
2010-03-07 20:03:04 +00:00
|
|
|
'http://www.testserver/middleware/customurlconf/slash/')
|
2011-03-01 14:28:06 +00:00
|
|
|
|
2011-05-05 20:49:26 +00:00
|
|
|
# Tests for the 404 error reporting via email
|
|
|
|
|
|
|
|
def test_404_error_reporting(self):
|
|
|
|
settings.IGNORABLE_404_URLS = (re.compile(r'foo'),)
|
|
|
|
settings.SEND_BROKEN_LINK_EMAILS = True
|
|
|
|
request = self._get_request('regular_url/that/does/not/exist')
|
|
|
|
request.META['HTTP_REFERER'] = '/another/url/'
|
|
|
|
response = self.client.get(request.path)
|
|
|
|
CommonMiddleware().process_response(request, response)
|
|
|
|
self.assertEqual(len(mail.outbox), 1)
|
|
|
|
self.assertIn('Broken', mail.outbox[0].subject)
|
|
|
|
|
|
|
|
def test_404_error_reporting_no_referer(self):
|
|
|
|
settings.IGNORABLE_404_URLS = (re.compile(r'foo'),)
|
|
|
|
settings.SEND_BROKEN_LINK_EMAILS = True
|
|
|
|
request = self._get_request('regular_url/that/does/not/exist')
|
|
|
|
response = self.client.get(request.path)
|
|
|
|
CommonMiddleware().process_response(request, response)
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
def test_404_error_reporting_ignored_url(self):
|
|
|
|
settings.IGNORABLE_404_URLS = (re.compile(r'foo'),)
|
|
|
|
settings.SEND_BROKEN_LINK_EMAILS = True
|
|
|
|
request = self._get_request('foo_url/that/does/not/exist/either')
|
|
|
|
request.META['HTTP_REFERER'] = '/another/url/'
|
|
|
|
response = self.client.get(request.path)
|
|
|
|
CommonMiddleware().process_response(request, response)
|
|
|
|
self.assertEqual(len(mail.outbox), 0)
|
|
|
|
|
|
|
|
|
2011-03-01 14:28:06 +00:00
|
|
|
class ConditionalGetMiddlewareTest(TestCase):
|
|
|
|
urls = 'regressiontests.middleware.cond_get_urls'
|
|
|
|
def setUp(self):
|
|
|
|
self.req = HttpRequest()
|
|
|
|
self.req.META = {
|
|
|
|
'SERVER_NAME': 'testserver',
|
|
|
|
'SERVER_PORT': 80,
|
|
|
|
}
|
|
|
|
self.req.path = self.req.path_info = "/"
|
|
|
|
self.resp = self.client.get(self.req.path)
|
|
|
|
|
|
|
|
# Tests for the Date header
|
|
|
|
|
|
|
|
def test_date_header_added(self):
|
|
|
|
self.assertFalse('Date' in self.resp)
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
|
|
|
self.assertTrue('Date' in self.resp)
|
|
|
|
|
|
|
|
# Tests for the Content-Length header
|
|
|
|
|
|
|
|
def test_content_length_header_added(self):
|
|
|
|
content_length = len(self.resp.content)
|
|
|
|
self.assertFalse('Content-Length' in self.resp)
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
|
|
|
self.assertTrue('Content-Length' in self.resp)
|
|
|
|
self.assertEqual(int(self.resp['Content-Length']), content_length)
|
|
|
|
|
|
|
|
def test_content_length_header_not_changed(self):
|
|
|
|
bad_content_length = len(self.resp.content) + 10
|
|
|
|
self.resp['Content-Length'] = bad_content_length
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
|
|
|
self.assertEqual(int(self.resp['Content-Length']), bad_content_length)
|
|
|
|
|
|
|
|
# Tests for the ETag header
|
|
|
|
|
|
|
|
def test_if_none_match_and_no_etag(self):
|
|
|
|
self.req.META['HTTP_IF_NONE_MATCH'] = 'spam'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_no_if_none_match_and_etag(self):
|
|
|
|
self.resp['ETag'] = 'eggs'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_if_none_match_and_same_etag(self):
|
|
|
|
self.req.META['HTTP_IF_NONE_MATCH'] = self.resp['ETag'] = 'spam'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 304)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_if_none_match_and_different_etag(self):
|
|
|
|
self.req.META['HTTP_IF_NONE_MATCH'] = 'spam'
|
|
|
|
self.resp['ETag'] = 'eggs'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
# Tests for the Last-Modified header
|
|
|
|
|
|
|
|
def test_if_modified_since_and_no_last_modified(self):
|
|
|
|
self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_no_if_modified_since_and_last_modified(self):
|
|
|
|
self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_if_modified_since_and_same_last_modified(self):
|
|
|
|
self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 304)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_if_modified_since_and_last_modified_in_the_past(self):
|
|
|
|
self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:35:44 GMT'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 304)
|
2011-03-01 14:28:06 +00:00
|
|
|
|
|
|
|
def test_if_modified_since_and_last_modified_in_the_future(self):
|
|
|
|
self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
|
|
|
|
self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:41:44 GMT'
|
|
|
|
self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
|
2011-03-03 15:04:39 +00:00
|
|
|
self.assertEqual(self.resp.status_code, 200)
|