Beispiel #1
0
 def browse(self, pkg_path, uri_tail):
     """
     Display pretty-printed XML contained in package item with URI ending
     with *uri_tail* in package at *pkg_path*.
     """
     pkg = Package.read(pkg_path)
     pkg_item = pkg.find_item_by_uri_tail(uri_tail)
     item_presenter = ItemPresenter(pkg_item)
     OpcView.pkg_item(item_presenter)
Beispiel #2
0
 def it_constructs_subclass_based_on_item_type(self, content_types_item_,
                                               rels_item_, xml_part_,
                                               binary_part_):
     cases = (
         (content_types_item_, 'ContentTypesPresenter'),
         (rels_item_, 'RelsItemPresenter'),
         (xml_part_, 'XmlPartPresenter'),
         (binary_part_, 'ItemPresenter'),
     )
     for pkg_item, expected_type_name in cases:
         item_presenter = ItemPresenter(pkg_item)
         assert type(item_presenter).__name__ == expected_type_name
Beispiel #3
0
 def it_can_format_rels_xml(self, ItemPresenter_xml_, rels_item_):
     # fixture ----------------------
     ItemPresenter_xml_.return_value = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n'
         '<Relationships>\n'
         '  <Relationship Id="rId1" Type="xyz" Target="foo"/>\n'
         '  <Relationship Id="rId2" Type="abc" Target="bar"/>\n'
         '  <Relationship Id="rId3" Type="mno" Target="baz"/>\n'
         '</Relationships>')
     rels_presenter = ItemPresenter(rels_item_)
     # verify -----------------------
     expected_text = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n'
         '<Relationships>\n'
         '  <Relationship Id="x" Type="abc" Target="bar"/>\n'
         '  <Relationship Id="x" Type="mno" Target="baz"/>\n'
         '  <Relationship Id="x" Type="xyz" Target="foo"/>\n'
         '</Relationships>')
     assert rels_presenter.text == expected_text
Beispiel #4
0
 def it_can_format_cti_xml(self, ItemPresenter_xml_, content_types_item_):
     # fixture ----------------------
     ItemPresenter_xml_.return_value = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n'
         '<Types>\n'
         '  <Default Extension="foo" ContentType="bar"/>\n'
         '  <Override PartName="foobar" ContentType="barfoo"/>\n'
         '  <Default Extension="bar" ContentType="foo"/>\n'
         '  <Override PartName="barfoo" ContentType="foobar"/>\n'
         '</Types>')
     content_types_presenter = ItemPresenter(content_types_item_)
     # verify -----------------------
     expected_text = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n'
         '<Types>\n'
         '  <Default Extension="bar" ContentType="foo"/>\n'
         '  <Default Extension="foo" ContentType="bar"/>\n'
         '  <Override PartName="barfoo" ContentType="foobar"/>\n'
         '  <Override PartName="foobar" ContentType="barfoo"/>\n'
         '</Types>')
     assert content_types_presenter.text == expected_text
Beispiel #5
0
 def it_can_format_part_xml(self, ItemPresenter_xml_, xml_part_):
     # fixture ----------------------
     cases = (
         # root w/no attrs is unchanged -----------------
         (('<?xml?>\n'
           '<foobar/>'), ('<?xml?>\n'
                          '<foobar/>')),
         # sort order: def_ns, nsdecls, attrs -----------
         (('<?xml?>\n'
           '<foobar foo="bar" xmlns:f="foo" xmlns:b="bar" xmlns="zoo" boo'
           '="far"/>'), ('<?xml?>\n'
                         '<foobar\n'
                         '    xmlns="zoo"\n'
                         '    xmlns:b="bar"\n'
                         '    xmlns:f="foo"\n'
                         '    boo="far"\n'
                         '    foo="bar"\n'
                         '    />')),
     )
     # verify -----------------------
     for part_xml, expected_xml in cases:
         ItemPresenter_xml_.return_value = part_xml
         part_presenter = ItemPresenter(xml_part_)
         assert part_presenter.text == expected_xml
Beispiel #6
0
 def it_can_pretty_format_the_xml_of_its_item(self, content_types_item_,
                                              foobar_elm_):
     """Note: tests integration with lxml.etree"""
     content_types_item_.element = foobar_elm_
     item_presenter = ItemPresenter(content_types_item_)
     assert item_presenter.xml == self.FOOBAR_XML
Beispiel #7
0
 def it_provides_a_normalized_path_string_for_the_pkg_item(self, pkg_item_):
     pkg_item_.path = 'foo\\bar'
     item_presenter = ItemPresenter(pkg_item_)
     assert item_presenter.filename == 'foo/bar'