예제 #1
0
def guess_xsd_type(obj):
    """Return the XSD Type for the given object"""
    if isinstance(obj, bool):
        return xsd.Boolean()
    if isinstance(obj, int):
        return xsd.Integer()
    if isinstance(obj, float):
        return xsd.Float()
    if isinstance(obj, datetime.datetime):
        return xsd.DateTime()
    if isinstance(obj, datetime.date):
        return xsd.Date()
    return xsd.String()
예제 #2
0
def test_nil_elements():
    custom_type = xsd.Element(
        '{http://tests.python-zeep.org/}container',
        xsd.ComplexType(
            xsd.Sequence([
                xsd.Element(
                    '{http://tests.python-zeep.org/}item_1',
                    xsd.ComplexType(
                        xsd.Sequence([
                            xsd.Element(
                                '{http://tests.python-zeep.org/}item_1_1',
                                xsd.String())
                        ]),
                    ),
                    nillable=True),
                xsd.Element(
                    '{http://tests.python-zeep.org/}item_2',
                    xsd.DateTime(), nillable=True),
                xsd.Element(
                    '{http://tests.python-zeep.org/}item_3',
                    xsd.String(), min_occurs=0, nillable=False),
                xsd.Element(
                    '{http://tests.python-zeep.org/}item_4',
                    xsd.ComplexType(
                        xsd.Sequence([
                            xsd.Element(
                                '{http://tests.python-zeep.org/}item_4_1',
                                xsd.String(), nillable=True)
                        ])
                    )
                ),
            ])
        ))
    obj = custom_type(item_1=None, item_2=None, item_3=None, item_4={})

    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
          <ns0:item_2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
          <ns0:item_4>
            <ns0:item_4_1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
          </ns0:item_4>
        </ns0:container>
      </document>
    """
    node = render_node(custom_type, obj)
    etree.cleanup_namespaces(node)
    assert_nodes_equal(expected, node)
예제 #3
0
def test_nil_elements():
    custom_type = xsd.Element(
        '{http://tests.python-zeep.org/}container',
        xsd.ComplexType(children=[
            xsd.Element('{http://tests.python-zeep.org/}item_1',
                        xsd.ComplexType(children=[
                            xsd.Element(
                                '{http://tests.python-zeep.org/}item_1_1',
                                xsd.String())
                        ]),
                        nillable=True),
            xsd.Element('{http://tests.python-zeep.org/}item_2',
                        xsd.DateTime(),
                        nillable=True),
            xsd.Element('{http://tests.python-zeep.org/}item_3',
                        xsd.String(),
                        min_occurs=0,
                        nillable=False),
            xsd.Element(
                '{http://tests.python-zeep.org/}item_4',
                xsd.ComplexType(children=[
                    xsd.Element('{http://tests.python-zeep.org/}item_4_1',
                                xsd.String(),
                                nillable=True)
                ])),
        ]))
    obj = custom_type(item_1=None, item_2=None, item_3=None, item_4={})

    expected = """
      <document>
        <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
          <ns0:item_1/>
          <ns0:item_2/>
          <ns0:item_4>
            <ns0:item_4_1/>
          </ns0:item_4>
        </ns0:container>
      </document>
    """
    node = render_node(custom_type, obj)
    assert_nodes_equal(expected, node)
예제 #4
0
# Create DCPushes for all of the data in your new Deal entry
for k, v in deal_fields.items():
    try:
        f = deal_fields[k]
    except KeyError:
        print(f'A value for Field {k} was not found in your data')
        sys.exit()
    p = factory.DCPush(EntryId=new_deal_id, FieldId=f.Id)
    if f.FieldType == 'Text':
        new_value = xsd.AnyObject(xsd.String(), new_entry[k])
    elif v.FieldType in 'Number':
        new_value = xsd.AnyObject(xsd.Decimal(), new_entry[k])
    elif v.FieldType == 'Date':
        new_value = xsd.AnyObject(
            xsd.DateTime(), dt.datetime.strptime(new_entry[k], '%m/%d/%Y'))
    elif v.FieldType == 'Boolean':
        if new_entry[k].lower() == 'yes':
            new_value = xsd.AnyObject(xsd.Boolean(), True)
        elif new_entry[k].lower() == 'no':
            new_value = xsd.AnyObject(xsd.Boolean(), False)
        else:
            new_value = None
    elif v.FieldType == 'Choice':
        choices = v.ChoiceValues.ChoiceFieldValue
        targets = new_entry[k].split(';')
        if v.IsMultiSelect:
            choice_ids = list()
            for t in targets:
                try:
                    choice = list(filter(lambda c: c.Name == t, choices))[0]