From 3d7e2e5021c74f0384726d65ce4e0c0dc55ef05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Chaves?= Date: Thu, 30 Jun 2022 17:42:51 +0200 Subject: [PATCH] Add a test for the data URI handler now taking the body into account --- tests/test_downloader_handlers.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_downloader_handlers.py b/tests/test_downloader_handlers.py index e9f890391..bbf641439 100644 --- a/tests/test_downloader_handlers.py +++ b/tests/test_downloader_handlers.py @@ -3,6 +3,7 @@ import os import shutil import sys import tempfile +from base64 import b64encode from typing import Optional, Type from unittest import mock @@ -1237,3 +1238,15 @@ class DataURITestCase(unittest.TestCase): request = Request("data:,") return self.download_request(request, self.spider).addCallback(_test) + + def test_body_mime_type(self): + """Test that the body, and not only the declared MIME type, is taken + into account when choosing a response class.""" + def _test(response): + self.assertIsInstance(response, HtmlResponse) + + html = '\n.' + base64_html = b64encode(html.encode()).decode() + data_uri = f'data:application/unknown;base64,{base64_html}' + request = Request(data_uri) + return self.download_request(request, self.spider).addCallback(_test)