Permalink
Browse files

Patch settings so tests pass outside of the example project

  • Loading branch information...
1 parent 0d114a2 commit e49b4ec2cf5a3cccac9fafd00cc007707fc6f4c9 @nosamanuel nosamanuel committed Sep 1, 2011
Showing with 19 additions and 0 deletions.
  1. +2 −0 armstrong/esi/tests/_utils.py
  2. +17 −0 armstrong/esi/tests/middleware.py
@@ -15,6 +15,8 @@ def inner(self, *args, **kwargs):
return inner
class TestCase(DjangoTestCase):
+ urls = 'armstrong.esi.tests.esi_support.urls'
+
def setUp(self):
self._original_settings = settings
fudge.clear_expectations()
@@ -51,6 +51,7 @@ def restore_settings(patches, added_settings):
delattr(settings, setting)
class TestMiddleware(TestCase):
+
@with_fake_request
def test_returns_unmodified_response_on_non_esi_response(self, request):
original_content = str(random.randint(1000, 2000))
@@ -71,10 +72,14 @@ def test_replaces_esi_tags_with_actual_response(self, request):
esi_tag = '<esi:include src="%s" />' % url
response.content = esi_tag
+ patch_data = patch_settings({'MIDDLEWARE_CLASSES': MIDDLEWARES})
+
result = full_process_response(request, response)
self.assertFalse(re.search(esi_tag, result.content), msg='sanity check')
self.assertEquals(result.content, str(rand))
+ restore_settings(*patch_data)
+
@with_fake_request
def test_replaces_esi_tags_in_gzipped_response(self, request):
request.provides('get_full_path').returns('/')
@@ -86,13 +91,17 @@ def test_replaces_esi_tags_in_gzipped_response(self, request):
esi_tag = '<esi:include src="/500chars/" />'
response.content = '%s%s%s' % ('z' * 250, esi_tag, 'z' * 250)
+ patch_data = patch_settings({'MIDDLEWARE_CLASSES': MIDDLEWARES})
+
result = full_process_response(request, response, gzip=True)
self.assertFalse(re.search(esi_tag, result.content), msg='sanity check')
self.assertTrue(result.get('Content-Encoding', None) == 'gzip')
gunzip_response_content(result)
self.assertTrue(re.search('a' * 500, result.content))
+ restore_settings(*patch_data)
+
@with_fake_request
def test_replaces_relative_url_esi(self, request):
rand = random.randint(100, 200)
@@ -107,10 +116,14 @@ def test_replaces_relative_url_esi(self, request):
response.content = esi_tag
fudge.clear_calls()
+ patch_data = patch_settings({'MIDDLEWARE_CLASSES': MIDDLEWARES})
+
result = full_process_response(request, response)
self.assertFalse(re.search(esi_tag, result.content), msg='sanity check')
self.assertEquals(result.content, str(rand))
+ restore_settings(*patch_data)
+
@with_fake_request
def check_content_permutation(self, request, permutation, chunk_results):
request_url = '/page-with-esi-tags/'
@@ -119,11 +132,15 @@ def check_content_permutation(self, request, permutation, chunk_results):
request.provides('build_absolute_uri').returns(
'http://example.com%s' % request_url)
+ patch_data = patch_settings({'MIDDLEWARE_CLASSES': MIDDLEWARES})
+
response = HttpResponse(''.join(permutation))
expected_result = ''.join(chunk_results[chunk] for chunk in permutation)
result = full_process_response(request, response)
self.assertEqual(result.content, expected_result)
+ restore_settings(*patch_data)
+
# TODO: This is a slow test that should be adjusted for so it doesn't take up
# > 80% of the execution time.
def test_replaces_multiple_esi_tags_correctly(self):

0 comments on commit e49b4ec

Please sign in to comment.