WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 52d8743

Browse files
tests: adjust mime type expectations for .rtf (#22)
The test checks the mime type of .rtf filename. The check is based on stdlib's `mimetypes.guess_type(name, strict=False)` which in turn depends on provider of mime types mapping. CPython's default mapping for rtf: https://github.com/python/cpython/blob/3.14/Lib/mimetypes.py#L650 https://github.com/python/cpython/blob/3.14/Lib/mimetypes.py#L678-L683 $ python3 -c 'import mimetypes; mimetypes.knownfiles=[]; mimetypes.init(); print(mimetypes.types_map[".rtf"])' text/rtf `mimetypes` tries next providers of mime data by default: $ python3 -c 'import mimetypes; print(mimetypes.knownfiles)' ['/etc/mime.types', '/etc/httpd/mime.types', '/etc/httpd/conf/mime.types', '/etc/apache/mime.types', '/etc/apache2/mime.types', '/usr/local/etc/httpd/conf/mime.types', '/usr/local/lib/netscape/mime.types', '/usr/local/etc/httpd/conf/mime.types', '/usr/local/etc/mime.types'] With installed /etc/mime.types (mailcap): $ python3 -c 'import mimetypes; mimetypes.init(); print(mimetypes.types_map[".rtf"])' application/rtf According to https://www.iana.org/assignments/media-types/media-types.xhtml both are possible. Fixes: #21 Signed-off-by: Stanislav Levin <[email protected]> Co-authored-by: Michael Howitz <[email protected]>
1 parent 5dab094 commit 52d8743

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/zope/contenttype/tests/testContentTypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def test_guess_content_type(self):
6060
ctype, _encoding = guess_content_type()
6161
self.assertEqual(ctype, "text/x-unknown-content-type")
6262
ctype, _encoding = guess_content_type("abc.rtf")
63-
self.assertEqual(ctype, "application/rtf")
63+
# both are possible
64+
self.assertIn(ctype, ("application/rtf", "text/rtf"))
6465

6566
def test_add_one_file(self):
6667
from zope.contenttype import add_files

0 commit comments

Comments
 (0)