File: test_input_parameters.py

package info (click to toggle)
suds 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,836 kB
  • sloc: python: 18,367; makefile: 198; sh: 41
file content (677 lines) | stat: -rw-r--r-- 25,709 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# -*- coding: utf-8 -*-

# This program is free software; you can redistribute it and/or modify it under
# the terms of the (LGPL) GNU Lesser General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Library Lesser General Public License
# for more details at ( http://www.gnu.org/licenses/lgpl.html ).
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# written by: Jurko Gospodnetić ( jurko.gospodnetic@pke.hr )

"""
Suds Python library web service operation input parameter related unit tests.

Suds provides the user with an option to automatically 'hide' wrapper elements
around simple types and allow the user to specify such parameters without
explicitly creating those wrappers. For example: operation taking a parameter
of type X, where X is a sequence containing only a single simple data type
(e.g. string or integer) will be callable by directly passing it that internal
simple data type value instead of first wrapping that value in an object of
type X and then passing that wrapper object instead.

Unit tests in this module make sure suds recognizes an operation's input
parameters in different scenarios as expected. It does not deal with binding
given argument values to an operation's input parameters or constructing an
actual binding specific web service operation invocation request, although they
may use such functionality as tools indicating that suds recognized an
operation's input parameters correctly.

"""

import testutils
if __name__ == "__main__":
    testutils.run_using_pytest(globals())

import suds

import pytest


class Element:
    """Represents elements in our XSD map test data."""

    def __init__(self, name):
        self.name = name


class XSDType:
    """Unwrapped parameter XSD type test data."""

    def __init__(self, xsd, xsd_map):
        self.xsd = xsd
        self.xsd_map = xsd_map


# Test data shared between different tests in this module.

choice_choice = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice>
          <xsd:element name="aString1" type="xsd:string" />
          <xsd:element name="anInteger1" type="xsd:integer" />
        </xsd:choice>
        <xsd:choice>
          <xsd:element name="aString2" type="xsd:string" />
          <xsd:element name="anInteger2" type="xsd:integer" minOccurs="0" />
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence", [
            "choice_1", [
                Element("aString1"),
                Element("anInteger1")],
            "choice_2", [
                Element("aString2"),
                Element("anInteger2")]]]])

choice_element_choice = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice>
          <xsd:element name="aString1" type="xsd:string" />
          <xsd:element name="anInteger1" type="xsd:integer" />
        </xsd:choice>
        <xsd:element name="separator" type="xsd:string" />
        <xsd:choice>
          <xsd:element name="aString2" type="xsd:string" />
          <xsd:element name="anInteger2" type="xsd:integer" minOccurs="0" />
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence", [
            "choice_1", [
                Element("aString1"),
                Element("anInteger1")],
            Element("separator"),
            "choice_2", [
                Element("aString2"),
                Element("anInteger2")]]]])

choice_simple_nonoptional = XSDType("""\
    <xsd:complexType>
      <xsd:choice>
        <xsd:element name="aString" type="xsd:string" />
        <xsd:element name="anInteger" type="xsd:integer" />
      </xsd:choice>
    </xsd:complexType>""", [
    "complex_type", [
        "choice", [
            Element("aString"),
            Element("anInteger")]]])

choice_with_element_and_two_element_sequence = XSDType("""\
    <xsd:complexType>
      <xsd:choice>
        <xsd:element name="a" type="xsd:integer" />
        <xsd:sequence>
          <xsd:element name="b1" type="xsd:integer" />
          <xsd:element name="b2" type="xsd:integer" />
        </xsd:sequence>
      </xsd:choice>
    </xsd:complexType>""", [
    "complex_type", [
        "choice", [
            Element("a"),
            "sequence", [
                Element("b1"),
                Element("b2")]]]])

empty_sequence = XSDType("""\
    <xsd:complexType>
      <xsd:sequence />
    </xsd:complexType>""", [
    "complex_type", [
        "sequence"]])

sequence_choice_with_element_and_two_element_sequence = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:choice>
          <xsd:element name="a" type="xsd:integer" />
          <xsd:sequence>
            <xsd:element name="b1" type="xsd:integer" />
            <xsd:element name="b2" type="xsd:integer" />
          </xsd:sequence>
        </xsd:choice>
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence_1", [
            "choice", [
                Element("a"),
                "sequence_2", [
                    Element("b1"),
                    Element("b2")]]]]])

sequence_with_five_elements = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="p1" type="xsd:string" />
        <xsd:element name="p2" type="xsd:integer" />
        <xsd:element name="p3" type="xsd:string" />
        <xsd:element name="p4" type="xsd:integer" />
        <xsd:element name="p5" type="xsd:string" />
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence", [
            Element("p1"),
            Element("p2"),
            Element("p3"),
            Element("p4"),
            Element("p5")]]])

sequence_with_one_element = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="param" type="xsd:integer" />
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence", [
            Element("param")]]])

sequence_with_two_elements = XSDType("""\
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="aString" type="xsd:string" />
        <xsd:element name="anInteger" type="xsd:integer" />
      </xsd:sequence>
    </xsd:complexType>""", [
    "complex_type", [
        "sequence", [
            Element("aString"),
            Element("anInteger")]]])


class TestUnsupportedParameterDefinitions:
    """
    Tests performed on WSDL schema's containing input parameter type
    definitions that can not be modeled using the currently implemented suds
    library input parameter definition structure.

    The tests included in this group, most of which are expected to fail,
    should serve as an illustration of what type of input parameter definitions
    still need to be better modeled. Once this has been done, they should be
    refactored into separate argument parsing, input parameter definition
    structure and binding specific request construction tests.

    """

    def expect_error(self, expected_error_text, *args, **kwargs):
        """
        Assert a test function call raises an expected TypeError exception.

        Caught exception is considered expected if its string representation
        matches the given expected error text.

        Expected error text may be given directly or as a list/tuple containing
        valid alternatives.

        Web service operation 'f' invoker is used as the default test function.
        An alternate test function may be specified using the 'test_function'
        keyword argument.

        """
        try:
            test_function = kwargs.pop("test_function")
        except KeyError:
            test_function = self.service.f
        e = pytest.raises(TypeError, test_function, *args, **kwargs).value
        try:
            if expected_error_text.__class__ in (list, tuple):
                assert str(e) in expected_error_text
            else:
                assert str(e) == expected_error_text
        finally:
            del e  # explicitly break circular reference chain in Python 3

    def init_function_params(self, params, **kwargs):
        """
        Initialize a test in this group with the given parameter definition.

        Constructs a complete WSDL schema based on the given function parameter
        definition (defines a single web service operation named 'f' by
        default), and creates a suds Client object to be used for testing
        suds's web service operation invocation.

        An alternate operation name may be given using the 'operation_name'
        keyword argument.

        May only be invoked once per test.

        """
        input = '<xsd:element name="Wrapper">%s</xsd:element>' % (params,)
        assert not hasattr(self, "service")
        wsdl = testutils.wsdl(input, input="Wrapper", **kwargs)
        client = testutils.client_from_wsdl(wsdl, nosend=True)
        self.service = client.service

    @pytest.mark.parametrize("test_args_required", (
        pytest.param(True, marks=pytest.mark.xfail(
            reason="empty choice member items not supported")),
        False))
    def test_choice_containing_an_empty_sequence(self, test_args_required):
        """
        Test reporting extra input parameters passed to a function taking a
        choice parameter group containing an empty sequence subgroup.

        """
        self.init_function_params("""\
          <xsd:complexType>
            <xsd:choice>
              <xsd:element name="a" type="xsd:integer" />
              <xsd:sequence>
              </xsd:sequence>
            </xsd:choice>
          </xsd:complexType>""")

        expected = "f() takes 0 to 1 positional arguments but 3 were given"
        if not test_args_required:
            expected = [expected,
                "f() takes 1 positional argument but 3 were given"]
        self.expect_error(expected, 1, None, None)

    @pytest.mark.parametrize("choice", (
        # Explicitly marked as optional and containing only non-optional
        # elements.
        pytest.param(
        """\
          <xsd:complexType>
            <xsd:choice minOccurs="0">
              <xsd:element name="aString" type="xsd:string" />
              <xsd:element name="anInteger" type="xsd:integer" />
            </xsd:choice>
          </xsd:complexType>""", marks=pytest.mark.xfail(
              reason="suds does not yet support minOccurs/"
              "maxOccurs attributes on all/choice/sequence order indicators")),
        # Explicitly marked as optional and containing at least one
        # non-optional element.
        """\
          <xsd:complexType>
            <xsd:choice minOccurs="0">
              <xsd:element name="aString" type="xsd:string" minOccurs="0" />
              <xsd:element name="anInteger" type="xsd:integer" />
            </xsd:choice>
          </xsd:complexType>""",
        """\
          <xsd:complexType>
            <xsd:choice minOccurs="0">
              <xsd:element name="aString" type="xsd:string" />
              <xsd:element name="anInteger" type="xsd:integer" minOccurs="0" />
            </xsd:choice>
          </xsd:complexType>""",
        """\
          <xsd:complexType>
            <xsd:choice minOccurs="0">
              <xsd:element name="aString" type="xsd:string" minOccurs="0" />
              <xsd:element name="anInteger" type="xsd:integer" minOccurs="0" />
            </xsd:choice>
          </xsd:complexType>"""))
    def test_choice_explicitly_marked_as_optional(self, choice):
        """
        Test reporting extra input parameters passed to a function taking a
        single optional choice parameter group.

        """
        self.init_function_params(choice)
        expected = "f() takes 0 to 2 positional arguments but 3 were given"
        self.expect_error(expected, "one", None, 3)


@pytest.mark.parametrize("part_name", ("uno", "due", "quatro"))
def test_builtin_typed_element_parameter(part_name):
    """
    Test correctly recognizing web service operation input structure defined by
    a built-in typed element.

    """
    wsdl = suds.byte_str("""\
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions targetNamespace="my-namespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns="my-namespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <xsd:schema targetNamespace="my-namespace"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="MyElement" type="xsd:integer" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="fRequestMessage">
    <wsdl:part name="%s" element="ns:MyElement" />
  </wsdl:message>
  <wsdl:portType name="dummyPortType">
    <wsdl:operation name="f">
      <wsdl:input message="ns:fRequestMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="dummy" type="ns:dummyPortType">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="f">
      <soap:operation soapAction="my-soap-action" style="document" />
      <wsdl:input><soap:body use="literal" /></wsdl:input>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="dummy">
    <wsdl:port name="dummy" binding="ns:dummy">
      <soap:address location="unga-bunga-location" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>""" % (part_name,))
    client = testutils.client_from_wsdl(wsdl, nosend=True)

    # Collect references to required WSDL model content.
    method = client.wsdl.services[0].ports[0].methods["f"]
    assert not method.soap.input.body.wrapped
    binding = method.binding.input
    assert binding.__class__ is suds.bindings.document.Document
    my_element = client.wsdl.schema.elements["MyElement", "my-namespace"]

    param_defs = binding.param_defs(method)
    _expect_params(param_defs, [("MyElement", my_element)])


@pytest.mark.parametrize("part_name", ("parameters", "pipi"))
def test_explicitly_wrapped_parameter(part_name):
    """
    Test correctly recognizing explicitly wrapped web service operation input
    structure which would otherwise be automatically unwrapped.

    """
    input_schema = sequence_choice_with_element_and_two_element_sequence.xsd
    wsdl = _unwrappable_wsdl(part_name, input_schema)
    client = testutils.client_from_wsdl(wsdl, nosend=True, unwrap=False)

    # Collect references to required WSDL model content.
    method = client.wsdl.services[0].ports[0].methods["f"]
    assert not method.soap.input.body.wrapped
    binding = method.binding.input
    assert binding.__class__ is suds.bindings.document.Document
    wrapper = client.wsdl.schema.elements["Wrapper", "my-namespace"]

    param_defs = binding.param_defs(method)
    _expect_params(param_defs, [("Wrapper", wrapper)])


@pytest.mark.parametrize("param_names", (
    [],
    ["parameters"],
    ["pipi"],
    ["fifi", "la", "fuff"]))
def test_typed_parameters(param_names):
    """
    Test correctly recognizing web service operation input structure defined
    with 0 or more typed input message part parameters.

    """
    wsdl = ["""\
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions targetNamespace="my-namespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns="my-namespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <xsd:schema targetNamespace="my-namespace"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:complexType name="MyType">
        <xsd:sequence>
          <xsd:element name="a" type="xsd:integer" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="fRequestMessage">"""]
    for x in param_names:
        part_def = '\n    <wsdl:part name="%s" type="ns:MyType" />' % (x,)
        wsdl.append(part_def)
    wsdl.append("""
  </wsdl:message>
  <wsdl:portType name="dummyPortType">
    <wsdl:operation name="f">
      <wsdl:input message="ns:fRequestMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="dummy" type="ns:dummyPortType">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="f">
      <soap:operation soapAction="my-soap-action" style="document" />
      <wsdl:input><soap:body use="literal" /></wsdl:input>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="dummy">
    <wsdl:port name="dummy" binding="ns:dummy">
      <soap:address location="unga-bunga-location" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>""")
    wsdl = suds.byte_str("".join(wsdl))
    client = testutils.client_from_wsdl(wsdl, nosend=True)

    # Collect references to required WSDL model content.
    method = client.wsdl.services[0].ports[0].methods["f"]
    assert not method.soap.input.body.wrapped
    binding = method.binding.input
    assert binding.__class__ is suds.bindings.document.Document
    my_type = client.wsdl.schema.types["MyType", "my-namespace"]

    # Construct expected parameter definitions.
    expected_param_defs = [
        (param_name, [suds.bindings.binding.PartElement, param_name, my_type])
        for param_name in param_names]

    param_defs = binding.param_defs(method)
    _expect_params(param_defs, expected_param_defs)


@pytest.mark.parametrize("xsd_type", (
    choice_choice,
    choice_element_choice,
    choice_simple_nonoptional,
    choice_with_element_and_two_element_sequence,
    empty_sequence,
    sequence_choice_with_element_and_two_element_sequence,
    sequence_with_five_elements,
    sequence_with_one_element,
    sequence_with_two_elements))
def test_unwrapped_parameter(xsd_type):
    """Test recognizing unwrapped web service operation input structures."""
    input_schema = sequence_choice_with_element_and_two_element_sequence.xsd
    wsdl = _unwrappable_wsdl("part_name", input_schema)
    client = testutils.client_from_wsdl(wsdl, nosend=True)

    # Collect references to required WSDL model content.
    method = client.wsdl.services[0].ports[0].methods["f"]
    assert method.soap.input.body.wrapped
    binding = method.binding.input
    assert binding.__class__ is suds.bindings.document.Document
    wrapper = client.wsdl.schema.elements["Wrapper", "my-namespace"]

    # Construct expected parameter definitions.
    xsd_map = sequence_choice_with_element_and_two_element_sequence.xsd_map
    expected_param_defs = _parse_schema_model(wrapper, xsd_map)

    param_defs = binding.param_defs(method)
    _expect_params(param_defs, expected_param_defs)


@pytest.mark.parametrize("part_name", ("parameters", "pipi"))
def test_unwrapped_parameter_part_name(part_name):
    """
    Unwrapped parameter's part name should not affect its parameter definition.

    """
    input_schema = sequence_choice_with_element_and_two_element_sequence.xsd
    wsdl = _unwrappable_wsdl(part_name, input_schema)
    client = testutils.client_from_wsdl(wsdl, nosend=True)

    # Collect references to required WSDL model content.
    method = client.wsdl.services[0].ports[0].methods["f"]
    assert method.soap.input.body.wrapped
    binding = method.binding.input
    assert binding.__class__ is suds.bindings.document.Document
    wrapper = client.wsdl.schema.elements["Wrapper", "my-namespace"]

    # Construct expected parameter definitions.
    xsd_map = sequence_choice_with_element_and_two_element_sequence.xsd_map
    expected_param_defs = _parse_schema_model(wrapper, xsd_map)

    param_defs = binding.param_defs(method)
    _expect_params(param_defs, expected_param_defs)


def _expect_params(param_defs, expected_param_defs):
    """
    Assert the given parameter definition content.

    Given expected parameter definition content may contain the expected
    parameter type instance or it may contain a list/tuple describing the type
    instead.

    Type description list/tuple is expected to contain the following:
      1. type object's class reference
      2. type object's 'name' attribute value.
      3. type object's resolved type instance reference

    """
    assert param_defs.__class__ is list
    assert len(param_defs) == len(expected_param_defs)
    for pdef, expected_pdef in zip(param_defs, expected_param_defs):
        assert len(expected_pdef) in (2, 3), "bad test data"
        assert pdef[0] == expected_pdef[0]  # name
        if expected_pdef[1].__class__ in (list, tuple):
            # type - class/name/type instance
            assert pdef[1].__class__ is expected_pdef[1][0]
            assert pdef[1].name == expected_pdef[1][1]
            assert pdef[1].resolve() is expected_pdef[1][2]
        else:
            assert pdef[1] is expected_pdef[1]  # type - exact instance
        assert pdef[2:] == expected_pdef[2:]  # ancestry - optional


def _parse_schema_model(root, schema_model_map):
    """
    Utility function for preparing the expected parameter definition structure
    based on an unwrapped input parameter's XSD type schema.

    Parses the XSD schema definition under a given XSD schema item and returns
    the expected parameter definition structure based on the given schema map.

    The schema map describes the expected hierarchy of items in the given XSD
    schema. Even though this information could be deduced from the XSD schema
    itself, that would require a much more complex implementation and this is
    supposed to be a simple testing utility.

    """
    schema_items = {}
    param_defs = []
    _parse_schema_model_r(schema_items, param_defs, [], root, schema_model_map)
    return param_defs


def _parse_schema_model_r(schema_items, param_defs, ancestry, parent,
        schema_model_map):
    """Recursive implementation detail for _parse_schema_model()."""
    prev = None
    ancestry = list(ancestry)
    ancestry.append(parent)
    n = 0
    for x in schema_model_map:
        if x.__class__ in (list, tuple):
            assert prev is not None, "bad schema model map"
            _parse_schema_model_r(schema_items, param_defs, ancestry, prev, x)
            continue
        item = parent.rawchildren[n]
        if isinstance(x, Element):
            x = x.name
            prev = None
            param_defs.append((x, item, ancestry))
        else:
            assert isinstance(x, str), "bad schema model map"
            prev = item
        assert x not in schema_items, "duplicate schema map item names"
        schema_items[x] = item
        n += 1
    assert len(parent.rawchildren) == n


def _unwrappable_wsdl(part_name, param_schema):
    """
    Return a WSDL schema byte string.

    The returned WSDL schema defines a single service definition with a single
    port containing a single function named 'f' taking automatically
    unwrappable input parameter using document/literal binding.

    The input parameter is defined as a single named input message part (name
    given via the 'part_name' argument) referencing an XSD schema element named
    'Wrapper' located in the 'my-namespace' namespace.

    The wrapper element's type definition (XSD schema string) is given via the
    'param_schema' argument.

    """
    return suds.byte_str("""\
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions targetNamespace="my-namespace"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns="my-namespace"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <xsd:schema targetNamespace="my-namespace"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:element name="Wrapper">
%(param_schema)s
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="fRequestMessage">
    <wsdl:part name="%(part_name)s" element="ns:Wrapper" />
  </wsdl:message>
  <wsdl:portType name="dummyPortType">
    <wsdl:operation name="f">
      <wsdl:input message="ns:fRequestMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="dummy" type="ns:dummyPortType">
    <soap:binding style="document"
    transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="f">
      <soap:operation soapAction="my-soap-action" style="document" />
      <wsdl:input><soap:body use="literal" /></wsdl:input>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="dummy">
    <wsdl:port name="dummy" binding="ns:dummy">
      <soap:address location="unga-bunga-location" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>""" % {"param_schema":param_schema, "part_name":part_name})