Beispiel #1
0
 def it_can_write_a_content_types_stream(self, write_cti_fixture):
     _ContentTypesItem_, parts_, phys_pkg_writer_, blob_ = (
         write_cti_fixture)
     PackageWriter._write_content_types_stream(phys_pkg_writer_, parts_)
     _ContentTypesItem_.from_parts.assert_called_once_with(parts_)
     phys_pkg_writer_.write.assert_called_once_with('/[Content_Types].xml',
                                                    blob_)
Beispiel #2
0
 def save(self, pkg_file):
     """
     Save this package to *pkg_file*, where *file* can be either a path to
     a file (a string) or a file-like object.
     """
     for part in self.parts:
         part.before_marshal()
     PackageWriter.write(pkg_file, self.rels, self.parts)
 def it_can_write_a_pkg_rels_item(self):
     # mockery ----------------------
     phys_writer = Mock(name="phys_writer")
     pkg_rels = Mock(name="pkg_rels")
     # exercise ---------------------
     PackageWriter._write_pkg_rels(phys_writer, pkg_rels)
     # verify -----------------------
     phys_writer.write.assert_called_once_with("/_rels/.rels", pkg_rels.xml)
Beispiel #4
0
 def it_can_write_a_pkg_rels_item(self):
     # mockery ----------------------
     phys_writer = Mock(name='phys_writer')
     pkg_rels = Mock(name='pkg_rels')
     # exercise ---------------------
     PackageWriter._write_pkg_rels(phys_writer, pkg_rels)
     # verify -----------------------
     phys_writer.write.assert_called_once_with('/_rels/.rels', pkg_rels.xml)
Beispiel #5
0
 def save(self, pkg_file):
     """
     Save this package to *pkg_file*, where *file* can be either a path to
     a file (a string) or a file-like object.
     """
     for part in self.parts:
         part.before_marshal()
     PackageWriter.write(pkg_file, self.rels, self.parts)
Beispiel #6
0
 def it_can_write_a_content_types_stream(self, write_cti_fixture):
     _ContentTypesItem_, parts_, phys_pkg_writer_, blob_ = (
         write_cti_fixture
     )
     PackageWriter._write_content_types_stream(phys_pkg_writer_, parts_)
     _ContentTypesItem_.from_parts.assert_called_once_with(parts_)
     phys_pkg_writer_.write.assert_called_once_with(
         '/[Content_Types].xml', blob_
     )
Beispiel #7
0
 def it_can_write_a_list_of_parts(self):
     # mockery ----------------------
     phys_writer = Mock(name='phys_writer')
     rels = MagicMock(name='rels')
     rels.__len__.return_value = 1
     part1 = Mock(name='part1', _rels=rels)
     part2 = Mock(name='part2', _rels=[])
     # exercise ---------------------
     PackageWriter._write_parts(phys_writer, [part1, part2])
     # verify -----------------------
     expected_calls = [
         call(part1.partname, part1.blob),
         call(part1.partname.rels_uri, part1._rels.xml),
         call(part2.partname, part2.blob),
     ]
     assert phys_writer.write.mock_calls == expected_calls
Beispiel #8
0
 def it_can_write_a_package(self, PhysPkgWriter_, _write_methods):
     # mockery ----------------------
     pkg_file = Mock(name='pkg_file')
     pkg_rels = Mock(name='pkg_rels')
     parts = Mock(name='parts')
     phys_writer = PhysPkgWriter_.return_value
     # exercise ---------------------
     PackageWriter.write(pkg_file, pkg_rels, parts)
     # verify -----------------------
     expected_calls = [
         call._write_content_types_stream(phys_writer, parts),
         call._write_pkg_rels(phys_writer, pkg_rels),
         call._write_parts(phys_writer, parts),
     ]
     PhysPkgWriter_.assert_called_once_with(pkg_file)
     assert _write_methods.mock_calls == expected_calls
     phys_writer.close.assert_called_once_with()