|
14 | 14 | from mock import call, Mock |
15 | 15 |
|
16 | 16 | from opc.package import ( |
17 | | - OpcPackage, Part, PartFactory, RelationshipCollection, Unmarshaller |
| 17 | + OpcPackage, Part, PartFactory, _Relationship, RelationshipCollection, |
| 18 | + Unmarshaller |
18 | 19 | ) |
19 | | -from opc.packuri import PACKAGE_URI |
| 20 | +from opc.packuri import PACKAGE_URI, PackURI |
20 | 21 |
|
21 | 22 | from .unitutil import class_mock, method_mock |
22 | 23 |
|
@@ -132,6 +133,43 @@ def it_constructs_a_part_instance(self, Part_): |
132 | 133 | assert part == Part_.return_value |
133 | 134 |
|
134 | 135 |
|
| 136 | +class Describe_Relationship(object): |
| 137 | + |
| 138 | + def it_remembers_construction_values(self): |
| 139 | + # test data -------------------- |
| 140 | + rId = 'rId9' |
| 141 | + reltype = 'reltype' |
| 142 | + target = Mock(name='target_part') |
| 143 | + external = False |
| 144 | + # exercise --------------------- |
| 145 | + rel = _Relationship(rId, reltype, target, None, external) |
| 146 | + # verify ----------------------- |
| 147 | + assert rel.rId == rId |
| 148 | + assert rel.reltype == reltype |
| 149 | + assert rel.target_part == target |
| 150 | + assert rel.is_external == external |
| 151 | + |
| 152 | + def it_should_raise_on_target_part_access_on_external_rel(self): |
| 153 | + rel = _Relationship(None, None, None, None, external=True) |
| 154 | + with pytest.raises(ValueError): |
| 155 | + rel.target_part |
| 156 | + |
| 157 | + def it_should_have_target_ref_for_external_rel(self): |
| 158 | + rel = _Relationship(None, None, 'target', None, external=True) |
| 159 | + assert rel.target_ref == 'target' |
| 160 | + |
| 161 | + def it_should_have_relative_ref_for_internal_rel(self): |
| 162 | + """ |
| 163 | + Internal relationships (TargetMode == 'Internal' in the XML) should |
| 164 | + have a relative ref, e.g. '../slideLayouts/slideLayout1.xml', for |
| 165 | + the target_ref attribute. |
| 166 | + """ |
| 167 | + part = Mock(name='part', partname=PackURI('/ppt/media/image1.png')) |
| 168 | + baseURI = '/ppt/slides' |
| 169 | + rel = _Relationship(None, None, part, baseURI) # external=False |
| 170 | + assert rel.target_ref == '../media/image1.png' |
| 171 | + |
| 172 | + |
135 | 173 | class DescribeRelationshipCollection(object): |
136 | 174 |
|
137 | 175 | @pytest.fixture |
|
0 commit comments