Skip to content

Commit c10df00

Browse files
author
Steve Canny
committed
add OpcPackage.rels
1 parent defea71 commit c10df00

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

opc/package.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Provides an API for manipulating Open Packaging Convention (OPC) packages.
1212
"""
1313

14+
from opc.packuri import PACKAGE_URI
1415
from opc.pkgreader import PackageReader
1516

1617

@@ -20,6 +21,10 @@ class OpcPackage(object):
2021
the :meth:`open` class method with a path to a package file or file-like
2122
object containing one.
2223
"""
24+
def __init__(self):
25+
super(OpcPackage, self).__init__()
26+
self._rels = RelationshipCollection(PACKAGE_URI.baseURI)
27+
2328
@staticmethod
2429
def open(pkg_file):
2530
"""
@@ -31,6 +36,14 @@ def open(pkg_file):
3136
Unmarshaller.unmarshal(pkg_reader, pkg, PartFactory)
3237
return pkg
3338

39+
@property
40+
def rels(self):
41+
"""
42+
Return a reference to the |RelationshipCollection| holding the
43+
relationships for this package.
44+
"""
45+
return self._rels
46+
3447

3548
class Part(object):
3649
"""
@@ -86,6 +99,14 @@ def __new__(cls, partname, content_type, blob):
8699
return Part(partname, content_type, blob)
87100

88101

102+
class RelationshipCollection(object):
103+
"""
104+
Collection object for |_Relationship| instances, having list semantics.
105+
"""
106+
def __init__(self, baseURI):
107+
super(RelationshipCollection, self).__init__()
108+
109+
89110
class Unmarshaller(object):
90111
"""
91112
Hosts static methods for unmarshalling a package from a |PackageReader|

tests/test_package.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
from mock import call, Mock
1515

1616
from opc.package import OpcPackage, Part, PartFactory, Unmarshaller
17+
from opc.packuri import PACKAGE_URI
1718

1819
from .unitutil import class_mock, method_mock
1920

2021

22+
@pytest.fixture
23+
def RelationshipCollection_(request):
24+
return class_mock('opc.package.RelationshipCollection', request)
25+
26+
2127
class DescribeOpcPackage(object):
2228

2329
@pytest.fixture
@@ -45,6 +51,12 @@ def it_can_open_a_pkg_file(self, PackageReader_, PartFactory_,
4551
PartFactory_)
4652
assert isinstance(pkg, OpcPackage)
4753

54+
def it_initializes_its_rels_collection_on_construction(
55+
self, RelationshipCollection_):
56+
pkg = OpcPackage()
57+
RelationshipCollection_.assert_called_once_with(PACKAGE_URI.baseURI)
58+
assert pkg.rels == RelationshipCollection_.return_value
59+
4860

4961
class DescribePart(object):
5062

0 commit comments

Comments
 (0)