Skip to content

Commit 3f60dbb

Browse files
author
Steve Canny
committed
opc: match Default on case-insensitive extension
1 parent c577869 commit 3f60dbb

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

docx/opc/pkgreader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class _ContentTypeMap(object):
118118
def __init__(self):
119119
super(_ContentTypeMap, self).__init__()
120120
self._overrides = CaseInsensitiveDict()
121-
self._defaults = dict()
121+
self._defaults = CaseInsensitiveDict()
122122

123123
def __getitem__(self, partname):
124124
"""

tests/opc/test_pkgreader.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,10 @@ def it_matches_an_override_on_case_insensitive_partname(
276276
ct_map, partname, content_type = match_override_fixture
277277
assert ct_map[partname] == content_type
278278

279-
def it_falls_back_to_defaults(self):
280-
ct_map = _ContentTypeMap()
281-
ct_map._overrides = {PackURI('/part/name1.xml'): 'app/vnd.type1'}
282-
ct_map._defaults = {'.xml': 'application/xml'}
283-
assert ct_map[PackURI('/part/name2.xml')] == 'application/xml'
279+
def it_falls_back_to_case_insensitive_extension_default_match(
280+
self, match_default_fixture):
281+
ct_map, partname, content_type = match_default_fixture
282+
assert ct_map[partname] == content_type
284283

285284
def it_should_raise_on_partname_not_found(self):
286285
ct_map = _ContentTypeMap()
@@ -299,7 +298,7 @@ def it_should_raise_on_key_not_instance_of_PackURI(self):
299298
def from_xml_fixture(self):
300299
entries = (
301300
('Default', 'xml', CT.XML),
302-
# ('Default', 'PNG', CT.PNG),
301+
('Default', 'PNG', CT.PNG),
303302
('Override', '/ppt/presentation.xml', CT.PML_PRESENTATION_MAIN),
304303
)
305304
content_types_xml = self._xml_from(entries)
@@ -315,6 +314,19 @@ def from_xml_fixture(self):
315314
expected_overrides[partname] = content_type
316315
return content_types_xml, expected_defaults, expected_overrides
317316

317+
@pytest.fixture(params=[
318+
('/foo/bar.xml', 'xml', 'application/xml'),
319+
('/foo/bar.PNG', 'png', 'image/png'),
320+
('/foo/bar.jpg', 'JPG', 'image/jpeg'),
321+
])
322+
def match_default_fixture(self, request):
323+
partname_str, ext, content_type = request.param
324+
partname = PackURI(partname_str)
325+
ct_map = _ContentTypeMap()
326+
ct_map._add_override(PackURI('/bar/foo.xyz'), 'application/xyz')
327+
ct_map._add_default(ext, content_type)
328+
return ct_map, partname, content_type
329+
318330
@pytest.fixture(params=[
319331
('/foo/bar.xml', '/foo/bar.xml'),
320332
('/foo/bar.xml', '/FOO/Bar.XML'),

0 commit comments

Comments
 (0)