Beispiel #1
0
 def sign_with_parent(self, private_key):
     if self._source_object:
         doc = etree.fromstring(self._source_object)
     else:
         doc = self.to_xml()
     self.parent_signature = create_relayable_signature(private_key, doc)
     add_element_to_doc(doc, "parent_author_signature", self.parent_signature)
     self.outbound_doc = doc
Beispiel #2
0
def test_add_element_to_doc():
    # Replacing value
    doc = etree.fromstring("<comment><text>foobar</text><parent_author_signature>barfoo</parent_author_signature>"
                           "</comment>")
    add_element_to_doc(doc, "parent_author_signature", "newsig")
    assert etree.tostring(doc) == b"<comment><text>foobar</text><parent_author_signature>newsig" \
                                  b"</parent_author_signature></comment>"
    # Adding value to an empty tag
    doc = etree.fromstring("<comment><text>foobar</text><parent_author_signature /></comment>")
    add_element_to_doc(doc, "parent_author_signature", "newsig")
    assert etree.tostring(doc) == b"<comment><text>foobar</text><parent_author_signature>newsig" \
                                  b"</parent_author_signature></comment>"
    # Adding missing tag
    doc = etree.fromstring("<comment><text>foobar</text></comment>")
    add_element_to_doc(doc, "parent_author_signature", "newsig")
    assert etree.tostring(doc) == b"<comment><text>foobar</text><parent_author_signature>newsig" \
                                  b"</parent_author_signature></comment>"