示例#1
0
def test_group_min_occurs_2():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Group(
                etree.QName('http://tests.python-zeep.org/', 'foobar'),
                xsd.Sequence([
                    xsd.Element(
                        etree.QName('http://tests.python-zeep.org/', 'item_1'),
                        xsd.String()),
                    xsd.Element(
                        etree.QName('http://tests.python-zeep.org/', 'item_2'),
                        xsd.String()),
                ]),
                min_occurs=2, max_occurs=2)
        ))
    expected = etree.fromstring("""
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
        </ns0:container>
    """)
    obj = custom_type.parse(expected, None)
    assert obj._value_1 == [
        {'item_1': 'foo', 'item_2': 'bar'},
        {'item_1': 'foo', 'item_2': 'bar'},
    ]
    assert not hasattr(obj, 'foobar')
示例#2
0
def test_build_group_min_occurs_1():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Group(etree.QName('http://tests.python-zeep.org/', 'foobar'),
                      xsd.Sequence([
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_1'), xsd.String()),
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_2'), xsd.String()),
                      ]),
                      min_occurs=1)))

    obj = custom_type(item_1='foo', item_2='bar')
    assert obj.item_1 == 'foo'
    assert obj.item_2 == 'bar'

    result = render_node(custom_type, obj)
    expected = load_xml("""
        <document>
          <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/">
            <ns0:item_1>foo</ns0:item_1>
            <ns0:item_2>bar</ns0:item_2>
          </ns0:authentication>
        </document>
    """)

    assert_nodes_equal(result, expected)

    obj = custom_type.parse(result[0], None)
    assert obj.item_1 == 'foo'
    assert obj.item_2 == 'bar'
    assert not hasattr(obj, 'foobar')
示例#3
0
def test_build_group_min_occurs_2_invalid_kwarg():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Group(
                etree.QName("http://tests.python-zeep.org/", "foobar"),
                xsd.Sequence(
                    [
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_1"),
                            xsd.String(),
                        ),
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_2"),
                            xsd.String(),
                        ),
                    ]
                ),
                min_occurs=2,
                max_occurs=2,
            )
        ),
    )

    with pytest.raises(TypeError):
        custom_type(
            _value_1=[
                {"item_1": "foo", "item_2": "bar", "error": True},
                {"item_1": "foo", "item_2": "bar"},
            ]
        )
示例#4
0
def test_build_group_min_occurs_2_invalid_kwarg():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Group(etree.QName('http://tests.python-zeep.org/', 'foobar'),
                      xsd.Sequence([
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_1'), xsd.String()),
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_2'), xsd.String()),
                      ]),
                      min_occurs=2,
                      max_occurs=2)))

    with pytest.raises(TypeError):
        custom_type(_value_1=[
            {
                'item_1': 'foo',
                'item_2': 'bar',
                'error': True
            },
            {
                'item_1': 'foo',
                'item_2': 'bar'
            },
        ])
示例#5
0
def test_group_mixed():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    etree.QName('http://tests.python-zeep.org/', 'username'),
                    xsd.String()),
                xsd.Group(
                    etree.QName('http://tests.python-zeep.org/', 'groupie'),
                    xsd.Sequence([
                        xsd.Element(
                            etree.QName('http://tests.python-zeep.org/',
                                        'password'),
                            xsd.String(),
                        )
                    ]))
            ])))
    assert custom_type.signature()
    obj = custom_type(username='******', password='******')

    expected = """
      <document>
        <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:username>foo</ns0:username>
          <ns0:password>bar</ns0:password>
        </ns0:authentication>
      </document>
    """
    node = etree.Element('document')
    custom_type.render(node, obj)
    assert_nodes_equal(expected, node)
示例#6
0
def test_build_group_occurs_1_invalid_kwarg():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Group(
                etree.QName("http://tests.python-zeep.org/", "foobar"),
                xsd.Sequence(
                    [
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_1"),
                            xsd.String(),
                        ),
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_2"),
                            xsd.String(),
                        ),
                    ]
                ),
                min_occurs=1,
                max_occurs=1,
            )
        ),
    )

    with pytest.raises(TypeError):
        custom_type(item_1="foo", item_2="bar", error=True)
示例#7
0
def test_build_group_min_occurs_1_parse_args():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Group(
                etree.QName("http://tests.python-zeep.org/", "foobar"),
                xsd.Sequence(
                    [
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_1"),
                            xsd.String(),
                        ),
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_2"),
                            xsd.String(),
                        ),
                    ]
                ),
                min_occurs=1,
            )
        ),
    )

    obj = custom_type("foo", "bar")
    assert obj.item_1 == "foo"
    assert obj.item_2 == "bar"
示例#8
0
def test_build_group_min_occurs_2():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Group(
                etree.QName("http://tests.python-zeep.org/", "foobar"),
                xsd.Sequence(
                    [
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_1"),
                            xsd.String(),
                        ),
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_2"),
                            xsd.String(),
                        ),
                    ]
                ),
                min_occurs=2,
                max_occurs=2,
            )
        ),
    )

    obj = custom_type(
        _value_1=[
            {"item_1": "foo", "item_2": "bar"},
            {"item_1": "foo", "item_2": "bar"},
        ]
    )
    assert obj._value_1 == [
        {"item_1": "foo", "item_2": "bar"},
        {"item_1": "foo", "item_2": "bar"},
    ]

    result = render_node(custom_type, obj)
    expected = load_xml(
        """
        <document>
          <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/">
            <ns0:item_1>foo</ns0:item_1>
            <ns0:item_2>bar</ns0:item_2>
            <ns0:item_1>foo</ns0:item_1>
            <ns0:item_2>bar</ns0:item_2>
          </ns0:authentication>
        </document>
    """
    )

    assert_nodes_equal(result, expected)

    obj = custom_type.parse(result[0], None)
    assert obj._value_1 == [
        {"item_1": "foo", "item_2": "bar"},
        {"item_1": "foo", "item_2": "bar"},
    ]
    assert not hasattr(obj, "foobar")
示例#9
0
def test_build_group_min_occurs_2_sequence_min_occurs_2():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Group(
                etree.QName("http://tests.python-zeep.org/", "foobar"),
                xsd.Sequence(
                    [
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_1"),
                            xsd.String(),
                        ),
                        xsd.Element(
                            etree.QName("http://tests.python-zeep.org/", "item_2"),
                            xsd.String(),
                        ),
                    ],
                    min_occurs=2,
                    max_occurs=2,
                ),
                min_occurs=2,
                max_occurs=2,
            )
        ),
    )
    expected = etree.fromstring(
        """
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
          <ns0:item_1>foo</ns0:item_1>
          <ns0:item_2>bar</ns0:item_2>
        </ns0:container>
    """
    )
    obj = custom_type.parse(expected, None)
    assert obj._value_1 == [
        {
            "_value_1": [
                {"item_1": "foo", "item_2": "bar"},
                {"item_1": "foo", "item_2": "bar"},
            ]
        },
        {
            "_value_1": [
                {"item_1": "foo", "item_2": "bar"},
                {"item_1": "foo", "item_2": "bar"},
            ]
        },
    ]
    assert not hasattr(obj, "foobar")
示例#10
0
def test_build_objects():
    custom_type = xsd.Element(
        etree.QName("http://tests.python-zeep.org/", "authentication"),
        xsd.ComplexType(
            xsd.Sequence(
                [
                    xsd.Element(
                        etree.QName("http://tests.python-zeep.org/", "username"),
                        xsd.String(),
                    ),
                    xsd.Group(
                        etree.QName("http://tests.python-zeep.org/", "groupie"),
                        xsd.Sequence(
                            [
                                xsd.Element(
                                    etree.QName(
                                        "http://tests.python-zeep.org/", "password"
                                    ),
                                    xsd.String(),
                                )
                            ]
                        ),
                    ),
                ]
            )
        ),
    )
    assert custom_type.signature()
    obj = custom_type(username="******", password="******")

    expected = """
      <document>
        <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:username>foo</ns0:username>
          <ns0:password>bar</ns0:password>
        </ns0:authentication>
      </document>
    """
    node = etree.Element("document")
    custom_type.render(node, obj)
    assert_nodes_equal(expected, node)

    obj = custom_type.parse(node[0], None)
    assert obj.username == "foo"
    assert obj.password == "bar"
示例#11
0
def test_build_group_min_occurs_1_parse_args():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Group(etree.QName('http://tests.python-zeep.org/', 'foobar'),
                      xsd.Sequence([
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_1'), xsd.String()),
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_2'), xsd.String()),
                      ]),
                      min_occurs=1)))

    obj = custom_type('foo', 'bar')
    assert obj.item_1 == 'foo'
    assert obj.item_2 == 'bar'
示例#12
0
def test_build_group_occurs_1_invalid_kwarg():
    custom_type = xsd.Element(
        etree.QName('http://tests.python-zeep.org/', 'authentication'),
        xsd.ComplexType(
            xsd.Group(etree.QName('http://tests.python-zeep.org/', 'foobar'),
                      xsd.Sequence([
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_1'), xsd.String()),
                          xsd.Element(
                              etree.QName('http://tests.python-zeep.org/',
                                          'item_2'), xsd.String()),
                      ]),
                      min_occurs=1,
                      max_occurs=1)))

    with pytest.raises(TypeError):
        custom_type(item_1='foo', item_2='bar', error=True)