Esempio n. 1
0
    def test_middleware_should_minify_only_when_status_code_is_200(self):
        response_mock = ResponseMock()
        response_mock.status_code = 301
        response = HtmlMinifyMiddleware().process_response(RequestMock(), response_mock)

        html_not_minified = "<html>   <body>some text here</body>    </html>"
        assert_equals(html_not_minified, response.content)
Esempio n. 2
0
 def test_should_minify_response_with_minify_response_true(self):
     minified = "<html><head></head><body>some text here</body></html>"
     response_mock = ResponseMock()
     response_mock.minify_response = True
     response = HtmlMinifyMiddleware().process_response(
         RequestMock(), response_mock,
     )
     self.assertEqual(minified, response.content)
Esempio n. 3
0
 def test_should_minify_response_with_minify_response_true(self):
     minified = "<html><head></head><body>some text here</body></html>"
     response_mock = ResponseMock()
     response_mock.minify_response = True
     response = HtmlMinifyMiddleware().process_response(
         RequestMock(),
         response_mock,
     )
     self.assertEqual(minified, response.content)
Esempio n. 4
0
    def test_should_minify_only_when_status_code_is_200(self):
        response_mock = ResponseMock()
        response_mock.status_code = 301
        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            response_mock,
        )

        html_not_minified = "<html>   <body>some text here</body>    </html>"
        self.assertEqual(html_not_minified, response.content)
Esempio n. 5
0
 def test_should_not_minify_url_marked_as_not_minifiable(self):
     html_not_minified = "<html>   <body>some text here</body>    </html>"
     response_mock = ResponseMock()
     response = HtmlMinifyMiddleware().process_response(
         RequestMock('/raw/'),
         response_mock,
     )
     self.assertEqual(html_not_minified, response.content)
Esempio n. 6
0
    def test_should_not_minify_when_request_did_not_hit_middleware(self):
        expected_output = "<html>   <body>some text here</body>    </html>"

        request_mock = RequestBareMock()
        response = HtmlMinifyMiddleware().process_response(
            request_mock,
            ResponseMock(),
        )
        self.assertEqual(expected_output, response.content)
Esempio n. 7
0
    def test_should_minify_response_when_mime_type_is_html(self):
        response_mock = ResponseMock()
        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            response_mock,
        )

        minified = "<html><head></head><body>some text here</body></html>"
        self.assertEqual(minified, response.content)
Esempio n. 8
0
    def test_should_not_minify_not_html_content(self):
        response_mock = ResponseMock()
        response_mock['Content-Type'] = 'application/json'
        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            response_mock,
        )

        html_not_minified = "<html>   <body>some text here</body>    </html>"
        self.assertEqual(html_not_minified, response.content)
Esempio n. 9
0
    def test_should_minify_with_any_charset(self):
        response_mock = ResponseMock()
        response_mock['Content-Type'] = 'text/html; charset=utf-8'
        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            response_mock,
        )

        minified = "<html><head></head><body>some text here</body></html>"
        self.assertEqual(minified, response.content)
Esempio n. 10
0
    def test_should_not_minify_if_the_HTML_MINIFY_setting_is_false(self):
        old = settings.HTML_MINIFY
        settings.HTML_MINIFY = False
        expected_output = "<html>   <body>some text here</body>    </html>"

        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            ResponseMock(),
        )
        self.assertEqual(expected_output, response.content)

        settings.HTML_MINIFY = old
Esempio n. 11
0
    def test_should_minify_if_exclude_from_minifying_is_unset(self):
        old = settings.EXCLUDE_FROM_MINIFYING
        del settings.EXCLUDE_FROM_MINIFYING

        minified = "<html><head></head><body>some text here</body></html>"
        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            ResponseMock(),
        )
        self.assertEqual(minified, response.content)

        settings.EXCLUDE_FROM_MINIFYING = old
Esempio n. 12
0
    def test_should_minify_when_DEBUG_is_false_and_MINIFY_is_unset(self):
        old = settings.HTML_MINIFY
        old_debug = settings.DEBUG
        del settings.HTML_MINIFY
        settings.DEBUG = False

        minified = "<html><head></head><body>some text here</body></html>"

        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            ResponseMock(),
        )
        self.assertEqual(minified, response.content)

        settings.DEBUG = old_debug
        settings.HTML_MINIFY = old
Esempio n. 13
0
    def test_should_not_minify_when_DEBUG_is_enabled(self):
        old = settings.HTML_MINIFY
        old_debug = settings.DEBUG
        del settings.HTML_MINIFY
        settings.DEBUG = True

        expected_output = "<html>   <body>some text here</body>    </html>"

        response = HtmlMinifyMiddleware().process_response(
            RequestMock(),
            ResponseMock(),
        )
        self.assertEqual(expected_output, response.content)

        settings.DEBUG = old_debug
        settings.HTML_MINIFY = old
Esempio n. 14
0
 def test_middleware_should_minify_if_response_has_minify_response_attribute_set_to_true(self):
     html_minified = "<!DOCTYPE html><html> <body>some text here</body> </html>"
     response_mock = ResponseMock()
     response_mock.minify_response = True
     response = HtmlMinifyMiddleware().process_response(RequestMock(), response_mock)
     assert_equals(html_minified, response.content)
 def test_should_not_minify_response_with_minify_response_false(self):
     html_not_minified = "<html>   <body>some text here</body>    </html>"
     response_mock = ResponseMock()
     response_mock.minify_response = False
     response = HtmlMinifyMiddleware().process_response(RequestMock(), response_mock)
     self.assertEqual(html_not_minified, response.content)