Exemplo n.º 1
0
def test_read(pyramid_oereb_test_config, status_code):
    response = {
        'results': [{
            'id': 702086,
            'weight': 4,
            'attrs': {
                'origin': 'address',
                'geom_quadindex': '021101213123030020322',
                'layerBodId': 'ch.bfs.gebaeude_wohnungs_register',
                'zoomlevel': 10,
                'featureId': '2355731_0',
                'lon': 7.728659152984619,
                'detail':
                'muehlemattstrasse 36 4410 liestal 2829 liestal ch bl',
                'rank': 7,
                'geom_st_box2d':
                'BOX(621857.447 259852.534,621857.447 259852.534)',
                'lat': 47.48907470703125,
                'num': 36,
                'y': 621857.4375,
                'x': 259852.53125,
                'label': 'Muehlemattstrasse 36 <b>4410 Liestal</b>'
            }
        }]
    }
    source = AddressGeoAdminSource(
        geoadmin_search_api=u'http://my.api.com/addresses')
    zip_code = 4410
    street_name = u'Muehlemattstrasse'
    street_number = u'36'
    url = u'http://my.api.com/addresses?' + urlencode({
        'searchText':
        u'{0} {1} {2}'.format(zip_code, street_name, street_number),
        'type':
        source._type,
        'origins':
        source._origins
    })
    with requests_mock.mock() as m:
        m.get(url, json=response, status_code=status_code)
        if status_code == 400:
            with pytest.raises(HTTPError):
                source.read(MockParameter(),
                            street_name=street_name,
                            zip_code=zip_code,
                            street_number=street_number)
        else:
            source.read(MockParameter(),
                        street_name=street_name,
                        zip_code=zip_code,
                        street_number=street_number)
            assert len(source.records) == 1
            address = source.records[0]
            assert isinstance(address, AddressRecord)
            assert address.street_number == u'36'
            assert address.zip_code == 4410
            assert address.street_name == u'Muehlemattstrasse'
            assert isinstance(address.geom, Point)
            assert address.geom.x == 2621857.986995669
            assert address.geom.y == 1259852.8231037268
def test_read_with_specified_language():
    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.1.1.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml?locale=fr', content=f.read())
        source = OEREBlexSource(host='http://oereblex.example.com', language='de', canton='BL')
        params = MockParameter()
        params.set_language('fr')
        source.read(params, 100)
        assert len(source.records) == 2
        document = source.records[0]
        assert document.responsible_office.name == {'fr': 'Landeskanzlei'}
        assert document.text_at_web == {
            'fr': 'http://oereblex.example.com/api/attachments/313'
        }
Exemplo n.º 3
0
def test_missing_parameter(pyramid_oereb_test_config):
    from pyramid_oereb.contrib.data_sources.standard.sources.real_estate import DatabaseSource

    source = DatabaseSource(**pyramid_oereb_test_config.get_real_estate_config(
    ).get('source').get('params'))
    with pytest.raises(AttributeError):
        source.read(MockParameter())
Exemplo n.º 4
0
def test_read_related_decree_as_main(oereblex_test_config):
    del oereblex_test_config

    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.2.2.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml',
                  content=f.read())
        source = OEREBlexSource(
            host='http://oereblex.example.com',
            language='de',
            canton='BL',
            version='1.2.2',
            related_decree_as_main=True,
            code='ch.Waldabstandslinien',
        )
        source.read(MockParameter(), 100)
        assert len(source.records) == 9
        document = source.records[0]
        assert isinstance(document, DocumentRecord)
        assert isinstance(document.responsible_office, OfficeRecord)
        assert document.responsible_office.name == {
            'de': 'Bauverwaltung Gemeinde'
        }
        assert document.text_at_web == {
            'de': 'http://oereblex.example.com/api/attachments/4735'
        }
        assert document.index == 30
Exemplo n.º 5
0
def test_read_related_notice_as_main(oereblex_test_config):
    del oereblex_test_config

    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.2.2.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml',
                  content=f.read())
        source = OEREBlexSource(
            host='http://oereblex.example.com',
            language='de',
            canton='BL',
            version='1.2.2',
            related_notice_as_main=True,
            code='ch.Waldabstandslinien',
        )
        source.read(MockParameter(), 100)
        assert len(source.records) == 9
        document = source.records[8]
        assert isinstance(document, DocumentRecord)
        assert isinstance(document.document_type, DocumentTypeRecord)
        assert document.document_type.code == 'Hint'
        assert isinstance(document.responsible_office, OfficeRecord)
        assert document.responsible_office.name == {'de': '-'}
        assert document.responsible_office.office_at_web is None
        assert document.published_from == datetime.date(1970, 1, 1)
        assert document.index == 40
Exemplo n.º 6
0
def test_read(param):
    source = DatabaseSource(
        **Config.get_real_estate_config().get('source').get('params'))
    source.read(MockParameter(), **param)
    assert len(source.records) == 1
    record = source.records[0]
    assert isinstance(record, RealEstateRecord)
    assert record.fosnr == 1234
Exemplo n.º 7
0
def test_read(pyramid_oereb_test_config, law_status_data):
    from pyramid_oereb.contrib.data_sources.standard.sources.law_status import DatabaseSource

    source = DatabaseSource(**pyramid_oereb_test_config.get_law_status_config(
    ).get('source').get('params'))
    source.read(MockParameter())
    assert isinstance(source.records, list)
    assert source.records[0].code == law_status_data[0].code
Exemplo n.º 8
0
def test_read(param, length):
    source = DatabaseSource(**Config.get_address_config().get('source').get('params'))
    source.read(MockParameter(), param.get('street_name'), param.get('zip_code'), param.get('street_number'))
    assert len(source.records) == length
    if length == 1:
        address = source.records[0]
        assert isinstance(address, AddressRecord)
        assert address.zip_code == 4410
def test_read(pyramid_oereb_test_config, disclaimer_data):
    from pyramid_oereb.contrib.data_sources.standard.sources.disclaimer import DatabaseSource

    source = DatabaseSource(**pyramid_oereb_test_config.get_disclaimer_config(
    ).get('source').get('params'))
    source.read(MockParameter())
    assert len(source.records) == 1
    assert source.records[0].title['de'] == disclaimer_data[0].title['de']
def test_read_with_specified_version():
    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.0.0.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/1.0.0/geolinks/100.xml', content=f.read())
        source = OEREBlexSource(host='http://oereblex.example.com', language='de', canton='BL',
                                pass_version=True, version='1.0.0')
        source.read(MockParameter(), 100)
        assert len(source.records) == 2
Exemplo n.º 11
0
def test_read(pyramid_oereb_test_config, municipality_data):
    from pyramid_oereb.contrib.data_sources.standard.sources.municipality import DatabaseSource

    source = DatabaseSource(**pyramid_oereb_test_config.get_municipality_config().get('source').get('params'))
    source.read(MockParameter())
    assert isinstance(source.records, list)
    assert len(source.records) == len(municipality_data)
    assert source.records[0].fosnr == municipality_data[0].fosnr
def test_read(pyramid_oereb_test_config, glossary_data):
    from pyramid_oereb.contrib.data_sources.standard.sources.glossary import DatabaseSource

    source = DatabaseSource(**pyramid_oereb_test_config.get_glossary_config().
                            get('source').get('params'))
    source.read(MockParameter())
    results = source.records
    assert len(results) == 1
    assert results[0].title['fr'] == glossary_data[0].title['fr']
Exemplo n.º 13
0
def test_read(param):
    reader = RealEstateReader(
        Config.get_real_estate_config().get('source').get('class'),
        **Config.get_real_estate_config().get('source').get('params')
    )
    records = reader.read(MockParameter(), **param)
    assert len(records) == 1
    record = records[0]
    assert isinstance(record, RealEstateRecord)
    assert record.fosnr == 1234
Exemplo n.º 14
0
def test_read(pyramid_oereb_test_config, real_estate_data, param):
    reader = RealEstateReader(
        pyramid_oereb_test_config.get_real_estate_config().get('source').get(
            'class'),
        **pyramid_oereb_test_config.get_real_estate_config().get('source').get(
            'params'))
    records = reader.read(MockParameter(), **param)
    assert len(records) == 1
    record = records[0]
    assert isinstance(record, RealEstateRecord)
    assert record.fosnr == real_estate_data[0].fosnr
Exemplo n.º 15
0
def test_read():
    reader = GlossaryReader(
        Config.get_glossary_config().get('source').get('class'),
        **Config.get_glossary_config().get('source').get('params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert isinstance(results[0], GlossaryRecord)
    assert len(results) == 1
    assert results[0].title['de'] == 'AGI'
    assert results[0].title['fr'] == 'SGRF'
    assert 'Geoinformation' in results[0].content['de']
Exemplo n.º 16
0
def test_read(pyramid_oereb_test_config, real_estate_data, param):
    from pyramid_oereb.contrib.data_sources.standard.sources.real_estate import DatabaseSource
    from pyramid_oereb.core.records.real_estate import RealEstateRecord

    source = DatabaseSource(**pyramid_oereb_test_config.get_real_estate_config(
    ).get('source').get('params'))
    source.read(MockParameter(), **param)
    assert len(source.records) == len(real_estate_data)
    record = source.records[0]
    assert isinstance(record, RealEstateRecord)
    assert record.fosnr == real_estate_data[0].fosnr
Exemplo n.º 17
0
def test_read(param, length):
    reader = AddressReader(
        Config.get_address_config().get('source').get('class'),
        **Config.get_address_config().get('source').get('params')
    )
    results = reader.read(MockParameter(), param.get('street_name'), param.get('zip_code'),
                          param.get('street_number'))
    assert len(results) == length
    if length == 1:
        address = results[0]
        assert isinstance(address, AddressRecord)
        assert address.zip_code == 4410
Exemplo n.º 18
0
def test_read(pyramid_oereb_test_config, glossary_data):
    reader = GlossaryReader(
        pyramid_oereb_test_config.get_glossary_config().get('source').get(
            'class'),
        **pyramid_oereb_test_config.get_glossary_config().get('source').get(
            'params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert isinstance(results[0], GlossaryRecord)
    assert len(results) == 1
    assert results[0].title['fr'] == glossary_data[0].title['fr']
    assert results[0].title['de'] == glossary_data[0].title['de']
    assert 'Geoinformation' in results[0].content['de']
Exemplo n.º 19
0
def test_read():
    reader = MunicipalityReader(
        Config.get_municipality_config().get('source').get('class'),
        **Config.get_municipality_config().get('source').get('params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert len(results) == 1
    result = results[0]
    assert isinstance(result, MunicipalityRecord)
    assert result.fosnr == 1234
    assert result.name == 'Test'
    assert result.published
    assert result.geom == 'MULTIPOLYGON (((0 0, 0 10, 10 10, 10 0, 0 0)))'
Exemplo n.º 20
0
def test_read(pyramid_oereb_test_config, address_data, param, length):
    from pyramid_oereb.contrib.data_sources.standard.sources.address import DatabaseSource
    from pyramid_oereb.core.records.address import AddressRecord

    source = DatabaseSource(**pyramid_oereb_test_config.get_address_config().
                            get('source').get('params'))
    source.read(MockParameter(), param.get('street_name'),
                param.get('zip_code'), param.get('street_number'))
    assert len(source.records) == length
    if length == 1:
        address = source.records[0]
        assert isinstance(address, AddressRecord)
        assert address.zip_code == address_data[0].zip_code
def test_read():
    reader = ExclusionOfLiabilityReader(
        Config.get_exclusion_of_liability_config().get('source').get('class'),
        **Config.get_exclusion_of_liability_config().get('source').get(
            'params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert len(results) == 1
    assert isinstance(results[0], ExclusionOfLiabilityRecord)
    assert len(results[0].title) == 4
    assert len(results[0].content) == 4
    assert 'du cadastre des sites' in results[0].title['fr']
    assert 'Kataster der belasteten Standorte' in results[0].content['de']
Exemplo n.º 22
0
def test_read(main_schema, land_use_plans, contaminated_sites, plr_sources,
              plr_cadastre_authority, real_estate, municipality):
    from pyramid_oereb.core.readers.extract import ExtractReader

    del main_schema, land_use_plans, contaminated_sites

    reader = ExtractReader(plr_sources, plr_cadastre_authority)
    extract = reader.read(MockParameter(), real_estate, municipality)
    assert isinstance(extract, ExtractRecord)
    plrs = extract.real_estate.public_law_restrictions
    assert isinstance(plrs, list)
    assert isinstance(plrs[0], PlrRecord)
    assert plrs[3].theme.code == 'ch.BelasteteStandorte'
    assert plrs[3].law_status.code == 'inForce'
Exemplo n.º 23
0
def test_read(pyramid_oereb_test_config, disclaimer_data):
    reader = DisclaimerReader(
        pyramid_oereb_test_config.get_disclaimer_config().get('source').get(
            'class'),
        **pyramid_oereb_test_config.get_disclaimer_config().get('source').get(
            'params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert len(results) == len(disclaimer_data)
    assert isinstance(results[0], DisclaimerRecord)
    assert len(results[0].title) == len(disclaimer_data[0].title)
    assert len(results[0].content) == len(disclaimer_data[0].content)
    assert 'du cadastre des sites' in results[0].title['fr']
    assert 'Kataster der belasteten Standorte' in results[0].content['de']
Exemplo n.º 24
0
def test_read(pyramid_oereb_test_config, address_data, param, length):
    from pyramid_oereb.core.readers.address import AddressReader

    reader = AddressReader(
        pyramid_oereb_test_config.get_address_config().get('source').get('class'),
        **pyramid_oereb_test_config.get_address_config().get('source').get('params')
    )
    results = reader.read(MockParameter(), param.get('street_name'), param.get('zip_code'),
                          param.get('street_number'))
    assert len(results) == length
    if length == 1:
        address = results[0]
        assert isinstance(address, AddressRecord)
        assert address.zip_code == address_data[0].zip_code
Exemplo n.º 25
0
def test_read(pyramid_oereb_test_config, municipality_data):
    reader = MunicipalityReader(
        pyramid_oereb_test_config.get_municipality_config().get('source').get(
            'class'),
        **pyramid_oereb_test_config.get_municipality_config().get(
            'source').get('params'))
    results = reader.read(MockParameter())
    assert isinstance(results, list)
    assert len(results) == 1
    result = results[0]
    expected = municipality_data[0]
    assert isinstance(result, MunicipalityRecord)
    assert result.fosnr == expected.fosnr
    assert result.name == expected.name
    assert result.published
Exemplo n.º 26
0
def test_read_with_specified_language(oereblex_test_config):
    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.2.2.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml?locale=fr',
                  content=f.read())
        source = OEREBlexSource(
            host='http://oereblex.example.com',
            language='de',
            canton='BL',
            version='1.2.2',
            code='ch.Waldabstandslinien',
        )
        params = MockParameter()
        params.set_language('fr')
        source.read(params, 100)
        assert len(source.records) == 9
        document = source.records[0]
        assert document.responsible_office.name == {
            'fr': 'Bauverwaltung Gemeinde'
        }
        assert document.text_at_web == {
            'fr': 'http://oereblex.example.com/api/attachments/4735'
        }
        assert document.index == 30
def test_read():
    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.1.1.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml', content=f.read())
        source = OEREBlexSource(host='http://oereblex.example.com', language='de', canton='BL')
        source.read(MockParameter(), 100)
        assert len(source.records) == 2
        document = source.records[0]
        assert isinstance(document, DocumentRecord)
        assert isinstance(document.responsible_office, OfficeRecord)
        assert document.responsible_office.name == {'de': 'Landeskanzlei'}
        assert document.canton == 'BL'
        assert document.text_at_web == {
            'de': 'http://oereblex.example.com/api/attachments/313'
        }
        assert len(document.references) == 5
Exemplo n.º 28
0
def test_read_with_specified_version(oereblex_test_config):
    del oereblex_test_config

    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.2.2.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/1.2.2/geolinks/100.xml',
                  content=f.read())
        source = OEREBlexSource(
            host='http://oereblex.example.com',
            language='de',
            canton='BL',
            version='1.2.2',
            pass_version=True,
            code='ch.Waldabstandslinien',
        )
        source.read(MockParameter(), 100)
        assert len(source.records) == 9
def test_read_related_notice_as_main():
    with requests_mock.mock() as m:
        with open('./tests/resources/geolink_v1.2.0.xml', 'rb') as f:
            m.get('http://oereblex.example.com/api/geolinks/100.xml',
                  content=f.read())
        source = OEREBlexSource(host='http://oereblex.example.com',
                                language='de',
                                canton='BL',
                                related_notice_as_main=True)
        source.read(MockParameter(), 100)
        assert len(source.records) == 6
        document = source.records[5]
        assert isinstance(document, HintRecord)
        assert isinstance(document.responsible_office, OfficeRecord)
        assert document.responsible_office.name == {'de': '-'}
        assert document.responsible_office.office_at_web is None
        assert document.published_from == datetime.date(1970, 1, 1)
        assert len(document.references) == 3
def test_read():
    source = DatabaseSource(**Config.get_glossary_config().get('source').get('params'))
    source.read(MockParameter())