Ejemplo n.º 1
0
 def test_missing_content_type(self):
     request = RequestFactory().get('/')
     response = HttpResponse('')
     del response['Content-Type']
     middleware = RandomCommentMiddleware()
     processed_response = middleware.process_response(request, response)
     self.assertEqual(response, processed_response)
Ejemplo n.º 2
0
 def test_missing_content_type(self):
     request = RequestFactory().get('/')
     response = HttpResponse('')
     del response['Content-Type']
     middleware = RandomCommentMiddleware()
     processed_response = middleware.process_response(request, response)
     self.assertEqual(response, processed_response)
Ejemplo n.º 3
0
    def test_exemption(self):
        html = '''<html>
    <head><title>Test</title></head>
    <body><p>Test body.</p></body>
</html>'''
        response = HttpResponse(html)
        response._random_comment_exempt = True
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertEqual(force_text(response.content), html)
Ejemplo n.º 4
0
    def test_exemption(self):
        html = '''<html>
    <head><title>Test</title></head>
    <body><p>Test body.</p></body>
</html>'''
        response = HttpResponse(html)
        response._random_comment_exempt = True
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertEqual(force_text(response.content), html)
Ejemplo n.º 5
0
    def test_unicode_characters(self):
        html = '''<!doctype html>
<html>
    <head>
        <title>Page title</title>
    </head>
    <body>
        <h1>Test</h1>
        <p>{0}</p>
    </body>
</html>'''.format(''.join(chr(x) for x in range(9999)))
        response = HttpResponse(html, content_type='text/html')
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertNotEqual(force_text(response.content), force_text(html))
Ejemplo n.º 6
0
    def test_html_content_type(self):
        html = '''<!doctype html>
<html>
    <head>
        <title>Page title</title>
    </head>
    <body>
        <h1>Test</h1>
        <p>Lorem ipsum</p>
    </body>
</html>'''
        response = HttpResponse(html, content_type='text/html')
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertNotEqual(response.content, html)
Ejemplo n.º 7
0
    def test_unicode_characters(self):
        html = '''<!doctype html>
<html>
    <head>
        <title>Page title</title>
    </head>
    <body>
        <h1>Test</h1>
        <p>{0}</p>
    </body>
</html>'''.format(''.join(chr(x) for x in range(9999)))
        response = HttpResponse(html, content_type='text/html')
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertNotEqual(force_text(response.content), force_text(html))
Ejemplo n.º 8
0
    def test_html_content_type(self):
        html = '''<!doctype html>
<html>
    <head>
        <title>Page title</title>
    </head>
    <body>
        <h1>Test</h1>
        <p>Lorem ipsum</p>
    </body>
</html>'''
        response = HttpResponse(html, content_type='text/html')
        request = RequestFactory().get('/')
        middleware = RandomCommentMiddleware()
        response = middleware.process_response(request, response)
        self.assertNotEqual(response.content, html)
Ejemplo n.º 9
0
 def test_empty_response_body_ignored(self):
     request = RequestFactory().get('/')
     response = HttpResponse('')
     middleware = RandomCommentMiddleware()
     processed_response = middleware.process_response(request, response)
     self.assertEqual(len(processed_response.content), 0)
Ejemplo n.º 10
0
 def test_noop_on_wrong_content_type(self):
     response = HttpResponse('abc', content_type='text/plain')
     request = RequestFactory().get('/')
     middleware = RandomCommentMiddleware()
     response = middleware.process_response(request, response)
     self.assertEqual(response.content, b'abc')
Ejemplo n.º 11
0
 def test_empty_response_body_ignored(self):
     request = RequestFactory().get('/')
     response = HttpResponse('')
     middleware = RandomCommentMiddleware()
     processed_response = middleware.process_response(request, response)
     self.assertEqual(len(processed_response.content), 0)
Ejemplo n.º 12
0
 def test_noop_on_wrong_content_type(self):
     response = HttpResponse('abc', content_type='text/plain')
     request = RequestFactory().get('/')
     middleware = RandomCommentMiddleware()
     response = middleware.process_response(request, response)
     self.assertEqual(response.content, b'abc')