|
14 | 14 | from mock import call, Mock, patch |
15 | 15 |
|
16 | 16 | from opc.phys_pkg import ZipPkgReader |
17 | | -from opc.pkgreader import _ContentTypeMap, PackageReader |
| 17 | +from opc.pkgreader import ( |
| 18 | + _ContentTypeMap, PackageReader, _SerializedRelationshipCollection |
| 19 | +) |
18 | 20 |
|
19 | 21 | from .unitutil import class_mock, initializer_mock, method_mock |
20 | 22 |
|
@@ -175,3 +177,36 @@ def it_can_retrieve_srels_for_a_source_uri( |
175 | 177 | phys_reader.rels_xml_for.assert_called_once_with(source_uri) |
176 | 178 | load_from_xml.assert_called_once_with(source_uri.baseURI, rels_xml) |
177 | 179 | assert retval == srels |
| 180 | + |
| 181 | + |
| 182 | +class Describe_SerializedRelationshipCollection(object): |
| 183 | + |
| 184 | + @pytest.fixture |
| 185 | + def oxml_fromstring(self, request): |
| 186 | + _patch = patch('opc.pkgreader.oxml_fromstring') |
| 187 | + request.addfinalizer(_patch.stop) |
| 188 | + return _patch.start() |
| 189 | + |
| 190 | + @pytest.fixture |
| 191 | + def _SerializedRelationship_(self, request): |
| 192 | + return class_mock('opc.pkgreader._SerializedRelationship', request) |
| 193 | + |
| 194 | + def it_can_load_from_xml(self, oxml_fromstring, _SerializedRelationship_): |
| 195 | + # mockery ---------------------- |
| 196 | + baseURI, rels_item_xml, rel_elm_1, rel_elm_2 = ( |
| 197 | + Mock(name='baseURI'), Mock(name='rels_item_xml'), |
| 198 | + Mock(name='rel_elm_1'), Mock(name='rel_elm_2'), |
| 199 | + ) |
| 200 | + rels_elm = Mock(name='rels_elm', Relationship=[rel_elm_1, rel_elm_2]) |
| 201 | + oxml_fromstring.return_value = rels_elm |
| 202 | + # exercise --------------------- |
| 203 | + srels = _SerializedRelationshipCollection.load_from_xml( |
| 204 | + baseURI, rels_item_xml) |
| 205 | + # verify ----------------------- |
| 206 | + expected_calls = [ |
| 207 | + call(baseURI, rel_elm_1), |
| 208 | + call(baseURI, rel_elm_2), |
| 209 | + ] |
| 210 | + oxml_fromstring.assert_called_once_with(rels_item_xml) |
| 211 | + assert _SerializedRelationship_.call_args_list == expected_calls |
| 212 | + assert isinstance(srels, _SerializedRelationshipCollection) |
0 commit comments