File: test_client_factory.py

package info (click to toggle)
python-zeep 4.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,600 kB
  • sloc: python: 15,551; makefile: 13
file content (44 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest

from zeep import Client


def test_factory_namespace():
    client = Client("tests/wsdl_files/soap.wsdl")
    factory = client.type_factory("http://example.com/stockquote.xsd")
    obj = factory.Address(NameFirst="Michael", NameLast="van Tellingen")
    assert obj.NameFirst == "Michael"
    assert obj.NameLast == "van Tellingen"


def test_factory_no_reference():
    client = Client("tests/wsdl_files/soap.wsdl")

    obj_1 = client.get_type("ns0:ArrayOfAddress")()
    obj_1.Address.append({"NameFirst": "J", "NameLast": "Doe"})
    obj_2 = client.get_type("ns0:ArrayOfAddress")()
    assert len(obj_2.Address) == 0


def test_factory_ns_auto_prefix():
    client = Client("tests/wsdl_files/soap.wsdl")
    factory = client.type_factory("ns0")
    obj = factory.Address(NameFirst="Michael", NameLast="van Tellingen")
    assert obj.NameFirst == "Michael"
    assert obj.NameLast == "van Tellingen"


def test_factory_ns_custom_prefix():
    client = Client("tests/wsdl_files/soap.wsdl")
    client.set_ns_prefix("sq", "http://example.com/stockquote.xsd")
    factory = client.type_factory("sq")
    obj = factory.Address(NameFirst="Michael", NameLast="van Tellingen")
    assert obj.NameFirst == "Michael"
    assert obj.NameLast == "van Tellingen"


def test_factory_ns_unknown_prefix():
    client = Client("tests/wsdl_files/soap.wsdl")

    with pytest.raises(ValueError):
        client.type_factory("bla")