Esempio n. 1
0
 def assert_is_invalid(self, xml_string, soapfish_schema):
     xml = etree.fromstring(xml_string)
     xmlschema = etree.XMLSchema(generate_xsd(soapfish_schema))
     assert_false(
         xmlschema.validate(xml),
         message="XML should fail to validate: %r" % xml_string
     )
Esempio n. 2
0
    def test_can_generate_schema_xml_containing_types_with_pattern_restriction(self):
        ns = 'http://soap.example/pattern.xsd'

        class Container(xsd.ComplexType):
            code = xsd.Element(xsd.String(pattern='[0-9]{0,5}'))
        schema = xsd.Schema(ns,
                            location=ns,
                            elementFormDefault=xsd.ElementFormDefault.QUALIFIED,
                            complexTypes=(
                                Container,
                            ),
                            elements={
                                'foo': xsd.Element(Container),
                            },
                            )
        # previously this would fail
        xsd_element = generate_xsd(schema)
        xmlschema = etree.XMLSchema(xsd_element)
        valid_xml = '<foo xmlns="%s"><code>1234</code></foo>' % ns

        def is_valid(s):
            return xmlschema.validate(etree.fromstring(s))
        assert_true(is_valid(valid_xml))

        bad_xml = '<foo xmlns="%s"><code>abc</code></foo>' % ns
        assert_false(is_valid(bad_xml))
Esempio n. 3
0
 def test_can_validate_soap_message(self):
     handler, handler_state = echo_handler()
     dispatcher = SOAPDispatcher(echo_service(handler))
     soap_message = (
         '<ns1:echoRequest xmlns:ns1="http://soap.example/echo/types">'
         '<invalid>foobar</invalid>'
         '</ns1:echoRequest>'
     )
     request_message = self._wrap_with_soap_envelope(soap_message)
     request = SOAPRequest(dict(SOAPACTION='echo', REQUEST_METHOD='POST'), request_message)
     response = dispatcher.dispatch(request)
     assert_false(handler_state.was_called)
     self.assert_is_soap_fault(response, partial_fault_string=u"Element 'invalid': This element is not expected. "
                               u"Expected is ( value ).")
Esempio n. 4
0
 def test_can_validate_soap_message(self):
     handler, handler_state = echo_handler()
     dispatcher = SOAPDispatcher(echo_service(handler))
     soap_message = (
         '<ns1:echoRequest xmlns:ns1="http://soap.example/echo/types">'
         '<invalid>foobar</invalid>'
         '</ns1:echoRequest>')
     request_message = self._wrap_with_soap_envelope(soap_message)
     request = SOAPRequest(dict(SOAPACTION='echo', REQUEST_METHOD='POST'),
                           request_message)
     response = dispatcher.dispatch(request)
     assert_false(handler_state.was_called)
     self.assert_is_soap_fault(
         response,
         partial_fault_string=
         u"Element 'invalid': This element is not expected. "
         u"Expected is ( value ).")
Esempio n. 5
0
 def assert_fail(self, value, message=None):
     return assert_raises(AssertionError,
                          lambda: assert_false(value, message=message))
Esempio n. 6
0
 def test_passes_if_value_is_false(self):
     assert_false(False)
Esempio n. 7
0
 def assert_is_invalid(self, xml_string, soapfish_schema):
     xml = etree.fromstring(xml_string)
     xmlschema = etree.XMLSchema(generate_xsd(soapfish_schema))
     assert_false(xmlschema.validate(xml),
                  message='XML should fail to validate: %r' % xml_string)
 def assert_fail(self, value, message=None):
     return assert_raises(AssertionError, lambda: assert_false(value, message=message))
 def test_passes_if_value_is_false(self):
     assert_false(False)