Skip to content

Commit e166178

Browse files
author
Steve Canny
committed
add PackageWriter._write_parts()
1 parent 8652073 commit e166178

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

opc/pkgwriter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def _write_parts(phys_writer, parts):
5353
Write the blob of each part in *parts* to the package, along with a
5454
rels item for its relationships if and only if it has any.
5555
"""
56-
raise NotImplementedError()
56+
for part in parts:
57+
phys_writer.write(part.partname, part.blob)
58+
if len(part._rels):
59+
phys_writer.write(part.partname.rels_uri, part._rels.xml)
5760

5861
@staticmethod
5962
def _write_pkg_rels(phys_writer, pkg_rels):

tests/test_pkgwriter.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pytest
1313

14-
from mock import call, Mock, patch
14+
from mock import call, MagicMock, Mock, patch
1515

1616
from opc.constants import CONTENT_TYPE as CT
1717
from opc.packuri import PackURI
@@ -90,6 +90,23 @@ def it_can_write_a_pkg_rels_item(self):
9090
phys_writer.write.assert_called_once_with('/_rels/.rels',
9191
pkg_rels.xml)
9292

93+
def it_can_write_a_list_of_parts(self):
94+
# mockery ----------------------
95+
phys_writer = Mock(name='phys_writer')
96+
rels = MagicMock(name='rels')
97+
rels.__len__.return_value = 1
98+
part1 = Mock(name='part1', _rels=rels)
99+
part2 = Mock(name='part2', _rels=[])
100+
# exercise ---------------------
101+
PackageWriter._write_parts(phys_writer, [part1, part2])
102+
# verify -----------------------
103+
expected_calls = [
104+
call(part1.partname, part1.blob),
105+
call(part1.partname.rels_uri, part1._rels.xml),
106+
call(part2.partname, part2.blob),
107+
]
108+
assert phys_writer.write.mock_calls == expected_calls
109+
93110

94111
class Describe_ContentTypesItem(object):
95112

0 commit comments

Comments
 (0)