|
8 | 8 |
|
9 | 9 | import pytest |
10 | 10 |
|
| 11 | +from docx.opc.coreprops import CoreProperties |
11 | 12 | from docx.opc.oxml import CT_Relationships |
12 | 13 | from docx.opc.packuri import PACKAGE_URI, PackURI |
13 | 14 | from docx.opc.package import ( |
14 | 15 | OpcPackage, Part, PartFactory, _Relationship, Relationships, |
15 | 16 | Unmarshaller, XmlPart |
16 | 17 | ) |
| 18 | +from docx.opc.parts.coreprops import CorePropertiesPart |
17 | 19 | from docx.opc.pkgreader import PackageReader |
18 | 20 | from docx.oxml.xmlchemy import BaseOxmlElement |
19 | 21 |
|
20 | 22 | from ..unitutil.cxml import element |
21 | 23 | from ..unitutil.mock import ( |
22 | 24 | call, class_mock, cls_attr_mock, function_mock, initializer_mock, |
23 | | - instance_mock, loose_mock, method_mock, Mock, patch, PropertyMock |
| 25 | + instance_mock, loose_mock, method_mock, Mock, patch, PropertyMock, |
| 26 | + property_mock |
24 | 27 | ) |
25 | 28 |
|
26 | 29 |
|
@@ -113,8 +116,53 @@ def it_can_save_to_a_pkg_file( |
113 | 116 | pkg_file_, pkg._rels, parts_ |
114 | 117 | ) |
115 | 118 |
|
| 119 | + def it_provides_access_to_the_core_properties(self, core_props_fixture): |
| 120 | + opc_package, core_properties_ = core_props_fixture |
| 121 | + core_properties = opc_package.core_properties |
| 122 | + assert core_properties is core_properties_ |
| 123 | + |
116 | 124 | # fixtures --------------------------------------------- |
117 | 125 |
|
| 126 | + @pytest.fixture |
| 127 | + def core_props_fixture( |
| 128 | + self, _core_properties_part_prop_, core_properties_part_, |
| 129 | + core_properties_): |
| 130 | + opc_package = OpcPackage() |
| 131 | + _core_properties_part_prop_.return_value = core_properties_part_ |
| 132 | + core_properties_part_.core_properties = core_properties_ |
| 133 | + return opc_package, core_properties_ |
| 134 | + |
| 135 | + @pytest.fixture |
| 136 | + def relate_to_part_fixture_(self, request, pkg, rels_, reltype): |
| 137 | + rId = 'rId99' |
| 138 | + rel_ = instance_mock(request, _Relationship, name='rel_', rId=rId) |
| 139 | + rels_.get_or_add.return_value = rel_ |
| 140 | + pkg._rels = rels_ |
| 141 | + part_ = instance_mock(request, Part, name='part_') |
| 142 | + return pkg, part_, reltype, rId |
| 143 | + |
| 144 | + @pytest.fixture |
| 145 | + def related_part_fixture_(self, request, rels_, reltype): |
| 146 | + related_part_ = instance_mock(request, Part, name='related_part_') |
| 147 | + rels_.part_with_reltype.return_value = related_part_ |
| 148 | + pkg = OpcPackage() |
| 149 | + pkg._rels = rels_ |
| 150 | + return pkg, reltype, related_part_ |
| 151 | + |
| 152 | + # fixture components ----------------------------------- |
| 153 | + |
| 154 | + @pytest.fixture |
| 155 | + def core_properties_(self, request): |
| 156 | + return instance_mock(request, CoreProperties) |
| 157 | + |
| 158 | + @pytest.fixture |
| 159 | + def core_properties_part_(self, request): |
| 160 | + return instance_mock(request, CorePropertiesPart) |
| 161 | + |
| 162 | + @pytest.fixture |
| 163 | + def _core_properties_part_prop_(self, request): |
| 164 | + return property_mock(request, OpcPackage, '_core_properties_part') |
| 165 | + |
118 | 166 | @pytest.fixture |
119 | 167 | def PackageReader_(self, request): |
120 | 168 | return class_mock(request, 'docx.opc.package.PackageReader') |
@@ -171,23 +219,6 @@ def rel_attrs_(self, request): |
171 | 219 | rId = 'rId99' |
172 | 220 | return reltype, target_, rId |
173 | 221 |
|
174 | | - @pytest.fixture |
175 | | - def relate_to_part_fixture_(self, request, pkg, rels_, reltype): |
176 | | - rId = 'rId99' |
177 | | - rel_ = instance_mock(request, _Relationship, name='rel_', rId=rId) |
178 | | - rels_.get_or_add.return_value = rel_ |
179 | | - pkg._rels = rels_ |
180 | | - part_ = instance_mock(request, Part, name='part_') |
181 | | - return pkg, part_, reltype, rId |
182 | | - |
183 | | - @pytest.fixture |
184 | | - def related_part_fixture_(self, request, rels_, reltype): |
185 | | - related_part_ = instance_mock(request, Part, name='related_part_') |
186 | | - rels_.part_with_reltype.return_value = related_part_ |
187 | | - pkg = OpcPackage() |
188 | | - pkg._rels = rels_ |
189 | | - return pkg, reltype, related_part_ |
190 | | - |
191 | 222 | @pytest.fixture |
192 | 223 | def rels_(self, request): |
193 | 224 | return instance_mock(request, Relationships) |
|
0 commit comments