|
14 | 14 | from mock import call, Mock, patch |
15 | 15 |
|
16 | 16 | from opc.constants import RELATIONSHIP_TARGET_MODE as RTM |
| 17 | +from opc.packuri import PackURI |
17 | 18 | from opc.phys_pkg import ZipPkgReader |
18 | 19 | from opc.pkgreader import ( |
19 | 20 | _ContentTypeMap, PackageReader, _SerializedRelationship, |
@@ -230,6 +231,33 @@ def it_can_construct_from_types_xml(self, oxml_fromstring): |
230 | 231 | assert ct_map._overrides == expected_overrides |
231 | 232 | assert ct_map._defaults == expected_defaults |
232 | 233 |
|
| 234 | + def it_matches_overrides(self): |
| 235 | + # test data -------------------- |
| 236 | + partname = PackURI('/part/name1.xml') |
| 237 | + content_type = 'app/vnd.type1' |
| 238 | + # fixture ---------------------- |
| 239 | + ct_map = _ContentTypeMap() |
| 240 | + ct_map._overrides = {partname: content_type} |
| 241 | + # verify ----------------------- |
| 242 | + assert ct_map[partname] == content_type |
| 243 | + |
| 244 | + def it_falls_back_to_defaults(self): |
| 245 | + ct_map = _ContentTypeMap() |
| 246 | + ct_map._overrides = {PackURI('/part/name1.xml'): 'app/vnd.type1'} |
| 247 | + ct_map._defaults = {'.xml': 'application/xml'} |
| 248 | + assert ct_map[PackURI('/part/name2.xml')] == 'application/xml' |
| 249 | + |
| 250 | + def it_should_raise_on_partname_not_found(self): |
| 251 | + ct_map = _ContentTypeMap() |
| 252 | + with pytest.raises(KeyError): |
| 253 | + ct_map[PackURI('/!blat/rhumba.1x&')] |
| 254 | + |
| 255 | + def it_should_raise_on_key_not_instance_of_PackURI(self): |
| 256 | + ct_map = _ContentTypeMap() |
| 257 | + ct_map._overrides = {PackURI('/part/name1.xml'): 'app/vnd.type1'} |
| 258 | + with pytest.raises(KeyError): |
| 259 | + ct_map['/part/name1.xml'] |
| 260 | + |
233 | 261 |
|
234 | 262 | class Describe_SerializedRelationship(object): |
235 | 263 |
|
|
0 commit comments