Пример #1
0
def test_choice_sequences_no_match():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Sequence([
                xsd.Element('item_1', xsd.String()),
                xsd.Element('item_2', xsd.String())
            ]),
            xsd.Sequence([
                xsd.Element('item_3', xsd.String()),
                xsd.Element('item_4', xsd.String())
            ]),
        ])),
    ]
    args = tuple([])
    kwargs = {'item_1': 'value-1', 'item_3': 'value-3'}

    try:
        utils.process_signature(fields, args, kwargs)
    except TypeError as exc:
        assert six.text_type(exc) == (
            "No complete xsd:Choice '_choice_1'.\n" +
            "The signature is: _choice_1: {item_1: xsd:string, item_2: xsd:string} " +
            "| {item_3: xsd:string, item_4: xsd:string}")
    else:
        assert False, "TypeError not raised"
Пример #2
0
def test_simple_args_too_few():
    fields = [
        ('item_1', xsd.Element('item_1', xsd.String())),
        ('item_2', xsd.Element('item_2', xsd.String()))
    ]
    args = tuple(['value-1'])
    kwargs = {}
    utils.process_signature(fields, args, kwargs)
Пример #3
0
def test_simple_args_too_many():
    fields = [
        ('item_1', xsd.Element('item_1', xsd.String())),
        ('item_2', xsd.Element('item_2', xsd.String()))
    ]
    args = tuple(['value-1', 'value-2', 'value-3'])
    kwargs = {}

    try:
        utils.process_signature(fields, args, kwargs)
    except TypeError as exc:
        assert six.text_type(exc) == (
            '__init__() takes at most 2 positional arguments (3 given)')
    else:
        assert False, "TypeError not raised"
Пример #4
0
    def __init__(self, *args, **kwargs):
        fields = self._xsd_type.fields()

        # Set default values
        for key, value, container in fields:
            if isinstance(value, ListElement):
                value = []
            else:
                value = None
            setattr(self, key, value)

        items = process_signature(fields, args, kwargs)
        fields = OrderedDict([(name, elm) for name, elm, container in fields])
        for key, value in items.items():
            field = fields[key]

            if isinstance(field, Any) and not isinstance(value, AnyObject):
                raise TypeError(
                    "%s: expected AnyObject, %s found" % (
                        key, type(value).__name__))

            if isinstance(value, dict):
                value = field(**value)

            elif isinstance(value, list):
                if isinstance(field.type, ComplexType):
                    value = [field.type(**v) for v in value]
                else:
                    value = [field.type(v) for v in value]

            setattr(self, key, value)
Пример #5
0
    def __init__(self, *args, **kwargs):
        fields = self._xsd_type.fields()

        # Set default values
        for key, value in fields:
            if isinstance(value, ListElement):
                value = []
            else:
                value = None
            setattr(self, key, value)

        items = process_signature(fields, args, kwargs)
        fields = OrderedDict([(name, elm) for name, elm in fields])
        for key, value in items.items():

            if key in fields:
                field = fields[key]

                if isinstance(field, Choice):
                    pass

                elif isinstance(value, dict):
                    value = field(**value)

                elif isinstance(value, list):
                    if isinstance(field.type, ComplexType):
                        value = [field.type(**v) for v in value]
                    else:
                        value = [field.type(v) for v in value]

            setattr(self, key, value)
Пример #6
0
    def __init__(self, *args, **kwargs):
        fields = OrderedDict([
            (prop.name, prop) for prop in self._xsd_type.properties()
        ])

        # Set default values
        for key, value in fields.items():
            if isinstance(value, ListElement):
                value = []
            else:
                value = None
            setattr(self, key, value)

        items = process_signature(fields.keys(), args, kwargs)
        for key, value in items.items():

            if isinstance(value, dict):
                value = fields[key](**value)

            elif isinstance(value, list):
                if isinstance(fields[key].type, ComplexType):
                    value = [fields[key].type(**v) for v in value]
                else:
                    value = [fields[key].type(v) for v in value]

            setattr(self, key, value)
Пример #7
0
    def __init__(self, *args, **kwargs):
        fields = self._xsd_type.fields()

        # Set default values
        for key, value in fields:
            if isinstance(value, ListElement):
                value = []
            else:
                value = None
            setattr(self, key, value)

        items = process_signature(fields, args, kwargs)
        fields = OrderedDict([(name, elm) for name, elm in fields])
        for key, value in items.items():

            if key in fields:
                field = fields[key]

                if isinstance(field, Choice):
                    pass

                elif isinstance(value, dict):
                    value = field(**value)

                elif isinstance(value, list):
                    if isinstance(field.type, ComplexType):
                        value = [field.type(**v) for v in value]
                    else:
                        value = [field.type(v) for v in value]

            setattr(self, key, value)
Пример #8
0
def test_choice_sequences_max_occur():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Sequence([
                xsd.Element('item_1', xsd.String()),
                xsd.Element('item_2', xsd.String())
            ]),
            xsd.Sequence([
                xsd.Element('item_2', xsd.String()),
                xsd.Element('item_3', xsd.String()),
            ]),
        ], max_occurs=2)),
    ]
    args = tuple([])
    kwargs = {
        '_choice_1': [
            {'item_1': 'value-1', 'item_2': 'value-2'},
            {'item_2': 'value-2', 'item_3': 'value-3'},
        ]
    }

    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        '_choice_1': [
            utils.ChoiceItem(0, {'item_1': 'value-1', 'item_2': 'value-2'}),
            utils.ChoiceItem(1, {'item_2': 'value-2', 'item_3': 'value-3'}),
        ]
    }
    def __init__(self, *args, **kwargs):
        fields = self._xsd_type.fields()

        # Set default values
        for key, value, container in fields:
            if isinstance(value, ListElement):
                value = []
            else:
                value = None
            setattr(self, key, value)

        items = process_signature(fields, args, kwargs)
        fields = OrderedDict([(name, elm) for name, elm, container in fields])
        for key, value in items.items():
            field = fields[key]

            if isinstance(field, Any) and not isinstance(value, AnyObject):
                raise TypeError("%s: expected AnyObject, %s found" %
                                (key, type(value).__name__))

            if isinstance(value, dict):
                value = field(**value)

            elif isinstance(value, list):
                if isinstance(field.type, ComplexType):
                    value = [field.type(**v) for v in value]
                else:
                    value = [field.type(v) for v in value]

            setattr(self, key, value)
Пример #10
0
def test_simple_mixed():
    fields = [
        ('item_1', xsd.Element('item_1', xsd.String())),
        ('item_2', xsd.Element('item_2', xsd.String()))
    ]
    args = tuple(['value-1'])
    kwargs = {'item_2': 'value-2'}
    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        'item_1': 'value-1',
        'item_2': 'value-2',
    }
Пример #11
0
def test_choice():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Element('item_1', xsd.String()),
            xsd.Element('item_2', xsd.String())
        ]))
    ]
    args = tuple([])
    kwargs = {'item_2': 'value-2'}
    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        '_choice_1': utils.ChoiceItem(1, {'item_2': 'value-2'})
    }
Пример #12
0
    def serialize(self, *args, **kwargs):
        soap = ElementMaker(namespace=self.nsmap['soap-env'], nsmap=self.nsmap)
        tag_name = etree.QName(
            self.namespace['body'], self.abstract.name.localname)

        body = soap.Body()
        method = etree.SubElement(body, tag_name)

        param_order = self.signature()
        items = process_signature(param_order, args, kwargs)
        for key, value in items.items():
            key = parse_qname(key, self.wsdl.nsmap, self.wsdl.target_namespace)
            obj = self.abstract.get_part(key)
            obj.render(method, value)
        return body, None, None
Пример #13
0
def test_choice_max_occurs_simple_interface():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Element('item_1', xsd.String()),
            xsd.Element('item_2', xsd.String())
        ], max_occurs=2))
    ]
    args = tuple([])
    kwargs = {
        'item_1': 'foo',
        'item_2': 'bar',
    }
    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        '_choice_1': [
            utils.ChoiceItem(0, {'item_1': 'foo'}),
            utils.ChoiceItem(1, {'item_2': 'bar'}),
        ]
    }
Пример #14
0
def test_choice_sequences_optional_elms():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Sequence([
                xsd.Element('item_1', xsd.String()),
                xsd.Element('item_2', xsd.String(), min_occurs=0)
            ]),
            xsd.Sequence([
                xsd.Element('item_1', xsd.String()),
                xsd.Element('item_2', xsd.String()),
                xsd.Element('item_3', xsd.String())
            ]),
        ])),
    ]
    args = tuple([])
    kwargs = {'item_1': 'value-1'}
    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        '_choice_1': utils.ChoiceItem(
            0, {'item_1': 'value-1', 'item_2': None})
    }
Пример #15
0
def test_choice_max_occurs_on_choice():
    fields = [
        ('_choice_1', xsd.Choice([
            xsd.Element('item_1', xsd.String(), max_occurs=2),
            xsd.Element('item_2', xsd.String())
        ], max_occurs=2))
    ]
    args = tuple([])
    kwargs = {
        '_choice_1': [
            {'item_1': ['foo', 'bar']},
            {'item_2': 'bla'},
        ]
    }
    result = utils.process_signature(fields, args, kwargs)
    assert result == {
        '_choice_1': [
            utils.ChoiceItem(0, {'item_1': ['foo', 'bar']}),
            utils.ChoiceItem(1, {'item_2': 'bla'})
        ]
    }