Exemple #1
0
class ShouldAdaptTests(unittest.TestCase):
    # tests for ImageAdaptingMiddleware.should_adapt

    def setUp(self):
        self.middleware = ImageAdaptingMiddleware(None, {})

    def test_no_content_type(self):
        # docs w/o content type should not be adapted
        request = Request.blank("http://localhost/test.html")
        response = request.get_response(wsgi_app_no_content_type)
        self.assertEqual(self.middleware.should_adapt(response), False)
        return

    def test_jpeg_content_type(self):
        # image/jpeg docs are adapted
        request = Request.blank("http://localhost/test.html")
        response = request.get_response(wsgi_app_img_jpg)
        self.assertEqual(self.middleware.should_adapt(response), True)
        return

    def test_gif_content_type(self):
        # image/gif docs are adapted
        request = Request.blank("http://localhost/test.html")
        response = request.get_response(wsgi_app_img_gif)
        self.assertEqual(self.middleware.should_adapt(response), True)
        return

    def test_png_content_type(self):
        # image/png docs are adapted
        request = Request.blank("http://localhost/test.html")
        response = request.get_response(wsgi_app_img_png)
        self.assertEqual(self.middleware.should_adapt(response), True)
        return