示例#1
0
def test_schema_fields_order(connector, create_datasource):
    schema_props_keys = list(
        JsonWrapper.loads(SoapDataSource.schema_json())['properties'].keys())
    assert schema_props_keys[0] == 'domain'
    assert schema_props_keys[1] == 'method'
    assert schema_props_keys[2] == 'parameters'
    assert schema_props_keys[3] == 'flatten_column'
示例#2
0
def test_serialized_response(mocker, connector, wsdl_sample, xml_response):
    """
    Check that the response type is a native python type,
    not a zeep object
    """

    responses.add('GET', 'https://example.com?wsdl', body=wsdl_sample)
    responses.add(
        'POST',
        'https://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso',
        body=xml_response,
    )

    ds = SoapDataSource(
        name='foosource',
        domain='test_domain',
        method='ListOfLanguagesByCode',
        parameters={},
    )
    expected = pd.DataFrame([{
        'sISOCode': 'FR',
        'sName': 'French'
    }, {
        'sISOCode': 'US',
        'sName': 'English'
    }])
    res = connector._retrieve_data(ds)
    assert res.equals(expected)
示例#3
0
def test__retrieve_data_list_of_dict_one_col_response(mocker, connector):
    """
    Check that the connector is able to retrieve data from SOAP API
    with scalar value
    """
    ds = SoapDataSource(
        name='foosource',
        domain='test_domain',
        method='fake_func',
        parameters={'arg': 'foo'},
    )

    def fake_func(arg: str):
        return [{'col1': ['fooo', 'barrr'], 'col2': ['boooo', 'farrrr']}]

    m = Mock()
    m.service.fake_func = fake_func
    mocker.patch(f'{import_path}.SoapConnector.create_client', return_value=m)
    data = connector._retrieve_data(ds)
    assert_frame_equal(
        data,
        pd.DataFrame({
            'col1': ['fooo', 'barrr'],
            'col2': ['boooo', 'farrrr']
        }),
    )
示例#4
0
def test__retrieve_data_dict_response(mocker, connector):
    """
    Check that the connector is able to retrieve data from SOAP API
    with scalar value
    """
    ds = SoapDataSource(
        name='foosource',
        domain='test_domain',
        method='fake_func',
        parameters={'arg': 'foo'},
    )

    def fake_func(arg: str):
        return {'title': 'Killing is my business ...and business is good'}

    m = Mock()
    m.service.fake_func = fake_func
    mocker.patch(f'{import_path}.SoapConnector.create_client', return_value=m)
    data = connector._retrieve_data(ds)
    assert_frame_equal(
        data,
        pd.DataFrame(
            {'title': 'Killing is my business ...and business is good'},
            index=[0]),
    )
示例#5
0
def test__retrieve_data(mocker, connector):
    """
    Check that the connector is able to retrieve data from SOAP API with nested
    response
    """
    ds = SoapDataSource(
        name='foosource',
        domain='test_domain',
        method='fake_func',
        parameters={'arg': 'foo'},
    )

    def fake_func(arg: str):
        """coucou"""
        return [{'id': 1, 'bla': 'bla'}, {'id': 2, 'bla': 'foo'}]

    m = Mock()
    m.service.fake_func = fake_func
    mocker.patch(f'{import_path}.SoapConnector.create_client', return_value=m)
    data = connector._retrieve_data(ds)
    assert_frame_equal(
        data,
        pd.DataFrame({
            'id': {
                0: 1,
                1: 2
            },
            'bla': {
                0: 'bla',
                1: 'foo'
            }
        }),
    )
示例#6
0
def create_datasource():
    return SoapDataSource(
        name='foosource',
        domain='test_domain',
        method='fake_func',
        parameters={'arg': 'foo'},
        flatten_column='nested',
    )