mirror of https://github.com/scrapy/scrapy.git
Improve test coverage for responsetypes.py (#7646)
* Improve test coverage for responsetypes.py * Solve typing issues
This commit is contained in:
parent
b6596de317
commit
7499d17e28
|
|
@ -40,18 +40,13 @@ class ResponseTypes:
|
|||
self.classes: dict[str, type[Response]] = {}
|
||||
self.mimetypes: MimeTypes = MimeTypes()
|
||||
mimedata = get_data("scrapy", "mime.types")
|
||||
if not mimedata:
|
||||
raise ValueError(
|
||||
"The mime.types file is not found in the Scrapy installation"
|
||||
)
|
||||
assert mimedata is not None
|
||||
self.mimetypes.readfp(StringIO(mimedata.decode("utf8")))
|
||||
for mimetype, cls in self.CLASSES.items():
|
||||
self.classes[mimetype] = load_object(cls)
|
||||
|
||||
def from_mimetype(self, mimetype: str) -> type[Response]:
|
||||
"""Return the most appropriate Response class for the given mimetype"""
|
||||
if mimetype is None:
|
||||
return Response
|
||||
if mimetype in self.classes:
|
||||
return self.classes[mimetype]
|
||||
basetype = f"{mimetype.split('/', maxsplit=1)[0]}/*"
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ class TestResponseTypes:
|
|||
retcls = responsetypes.from_content_disposition(source)
|
||||
assert retcls is cls, f"{source} ==> {retcls} != {cls}"
|
||||
|
||||
def test_from_content_disposition_no_filename(self):
|
||||
assert responsetypes.from_content_disposition(b"attachment") is Response
|
||||
|
||||
def test_from_content_type(self):
|
||||
mappings = [
|
||||
("text/html; charset=UTF-8", HtmlResponse),
|
||||
|
|
|
|||
Loading…
Reference in New Issue