Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
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)
Esempio n. 4
0
 def it_can_write_a_content_types_stream(self, xml_for):
     # mockery ----------------------
     phys_writer = Mock(name='phys_writer')
     parts = Mock(name='parts')
     # exercise ---------------------
     PackageWriter._write_content_types_stream(phys_writer, parts)
     # verify -----------------------
     xml_for.assert_called_once_with(parts)
     phys_writer.write.assert_called_once_with('/[Content_Types].xml',
                                               xml_for.return_value)
Esempio n. 5
0
 def it_can_write_a_content_types_stream(self, xml_for,
                                         serialize_part_xml_):
     # mockery ----------------------
     phys_writer = Mock(name='phys_writer')
     parts = Mock(name='parts')
     # exercise ---------------------
     PackageWriter._write_content_types_stream(phys_writer, parts)
     # verify -----------------------
     xml_for.assert_called_once_with(parts)
     serialize_part_xml_.assert_called_once_with(xml_for.return_value)
     phys_writer.write.assert_called_once_with(
         '/[Content_Types].xml', serialize_part_xml_.return_value)
Esempio n. 6
0
 def it_can_write_a_content_types_stream(self, xml_for, serialize_part_xml_):
     # mockery ----------------------
     phys_writer = Mock(name="phys_writer")
     parts = Mock(name="parts")
     # exercise ---------------------
     PackageWriter._write_content_types_stream(phys_writer, parts)
     # verify -----------------------
     xml_for.assert_called_once_with(parts)
     serialize_part_xml_.assert_called_once_with(xml_for.return_value)
     phys_writer.write.assert_called_once_with(
         "/[Content_Types].xml", serialize_part_xml_.return_value
     )
Esempio n. 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
Esempio n. 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()