def test_sign_request_with_issuer(self):
     root = Element(Q_NAMES['saml2p:AuthnRequest'])
     SubElement(root, Q_NAMES['saml2:Issuer'])
     request = SAMLRequest(ElementTree(root))
     request.sign_request(**SIGNATURE_OPTIONS)
     self.assertIsNotNone(request.request_signature)
     self.assertEqual(root.index(request.request_signature), 1)
 def test_sign_request_already_exists(self):
     root = Element(Q_NAMES['saml2p:AuthnRequest'])
     signature = SubElement(root, Q_NAMES['ds:Signature'])
     SubElement(root, Q_NAMES['saml2:Issuer'])
     request = SAMLRequest(ElementTree(root))
     with self.assertRaisesMessage(SecurityError,
                                   'Request signature already exists.'):
         request.sign_request(**SIGNATURE_OPTIONS)
     self.assertIs(request.request_signature, signature)