|
13 | 13 |
|
14 | 14 | from mock import call, Mock, patch
|
15 | 15 |
|
| 16 | +from opc.constants import CONTENT_TYPE as CT |
| 17 | +from opc.packuri import PackURI |
16 | 18 | from opc.pkgwriter import _ContentTypesItem, PackageWriter
|
17 | 19 |
|
18 |
| -from .unitutil import method_mock |
| 20 | +from .unitutil import function_mock, method_mock |
19 | 21 |
|
20 | 22 |
|
21 | 23 | class DescribePackageWriter(object):
|
@@ -77,3 +79,53 @@ def it_can_write_a_content_types_stream(self, xml_for):
|
77 | 79 | xml_for.assert_called_once_with(parts)
|
78 | 80 | phys_writer.write.assert_called_once_with('/[Content_Types].xml',
|
79 | 81 | xml_for.return_value)
|
| 82 | + |
| 83 | + |
| 84 | +class Describe_ContentTypesItem(object): |
| 85 | + |
| 86 | + @pytest.fixture |
| 87 | + def oxml_tostring(self, request): |
| 88 | + return function_mock('opc.pkgwriter.oxml_tostring', request) |
| 89 | + |
| 90 | + @pytest.fixture |
| 91 | + def parts(self): |
| 92 | + """list of parts that will exercise _ContentTypesItem.xml_for()""" |
| 93 | + return [ |
| 94 | + Mock(name='part_1', partname=PackURI('/docProps/core.xml'), |
| 95 | + content_type='app/vnd.core'), |
| 96 | + Mock(name='part_2', partname=PackURI('/docProps/thumbnail.jpeg'), |
| 97 | + content_type=CT.JPEG), |
| 98 | + Mock(name='part_3', partname=PackURI('/ppt/slides/slide2.xml'), |
| 99 | + content_type='app/vnd.ct_sld'), |
| 100 | + Mock(name='part_4', partname=PackURI('/ppt/slides/slide1.xml'), |
| 101 | + content_type='app/vnd.ct_sld'), |
| 102 | + Mock(name='part_5', partname=PackURI('/zebra/foo.bar'), |
| 103 | + content_type='app/vnd.foobar'), |
| 104 | + ] |
| 105 | + |
| 106 | + @pytest.fixture |
| 107 | + def types(self, request): |
| 108 | + """Mock returned by CT_Types.new() call""" |
| 109 | + types = Mock(name='types') |
| 110 | + _patch = patch('opc.pkgwriter.CT_Types') |
| 111 | + CT_Types = _patch.start() |
| 112 | + CT_Types.new.return_value = types |
| 113 | + request.addfinalizer(_patch.stop) |
| 114 | + return types |
| 115 | + |
| 116 | + def it_can_compose_content_types_xml(self, parts, types, oxml_tostring): |
| 117 | + # # exercise --------------------- |
| 118 | + _ContentTypesItem.xml_for(parts) |
| 119 | + # verify ----------------------- |
| 120 | + expected_types_calls = [ |
| 121 | + call.add_default('.jpeg', CT.JPEG), |
| 122 | + call.add_default('.rels', CT.OPC_RELATIONSHIPS), |
| 123 | + call.add_default('.xml', CT.XML), |
| 124 | + call.add_override('/docProps/core.xml', 'app/vnd.core'), |
| 125 | + call.add_override('/ppt/slides/slide1.xml', 'app/vnd.ct_sld'), |
| 126 | + call.add_override('/ppt/slides/slide2.xml', 'app/vnd.ct_sld'), |
| 127 | + call.add_override('/zebra/foo.bar', 'app/vnd.foobar'), |
| 128 | + ] |
| 129 | + assert types.mock_calls == expected_types_calls |
| 130 | + oxml_tostring.assert_called_once_with(types, encoding='UTF-8', |
| 131 | + standalone=True), |
0 commit comments