示例#1
0
def init_processor():
    global processor

    real_estate_config = Config.get_real_estate_config()
    municipality_config = Config.get_municipality_config()
    exclusion_of_liability_config = Config.get_exclusion_of_liability_config()
    glossary_config = Config.get_glossary_config()
    extract = Config.get_extract_config()
    certification = extract.get('certification')
    certification_at_web = extract.get('certification_at_web')
    logos = Config.get_logo_config()

    plr_cadastre_authority = Config.get_plr_cadastre_authority()

    real_estate_reader = RealEstateReader(
        real_estate_config.get('source').get('class'),
        **real_estate_config.get('source').get('params'))

    municipality_reader = MunicipalityReader(
        municipality_config.get('source').get('class'),
        **municipality_config.get('source').get('params'))

    exclusion_of_liability_reader = ExclusionOfLiabilityReader(
        exclusion_of_liability_config.get('source').get('class'),
        **exclusion_of_liability_config.get('source').get('params'))

    glossary_reader = GlossaryReader(
        glossary_config.get('source').get('class'),
        **glossary_config.get('source').get('params'))

    plr_sources = []
    for plr in Config.get('plrs'):
        plr_source_class = DottedNameResolver().maybe_resolve(
            plr.get('source').get('class'))
        plr_sources.append(plr_source_class(**plr))

    extract_reader = ExtractReader(
        plr_sources,
        plr_cadastre_authority,
        logos,
        certification,
        certification_at_web,
    )

    processor = Processor(
        real_estate_reader=real_estate_reader,
        municipality_reader=municipality_reader,
        exclusion_of_liability_reader=exclusion_of_liability_reader,
        glossary_reader=glossary_reader,
        plr_sources=plr_sources,
        extract_reader=extract_reader,
    )
示例#2
0
def test_missing_params():
    with pytest.raises(TypeError):
        Processor()
示例#3
0
def test_processor_get_legend_entries():
    theme1 = ThemeRecord(u'TEST', {'de': 'Theme 1'})
    theme2 = ThemeRecord(u'TEST', {'de': 'Theme 2'})
    office = OfficeRecord({'de': 'Test Office'})
    law_status = LawStatusRecord.from_config(u'inForce')
    geometries = [
        GeometryRecord(law_status, datetime.date.today(), Point(1, 1))
    ]
    legend1 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend1'},
                                'CodeA',
                                'bla',
                                theme1,
                                view_service_id=1)
    legend2 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend2'},
                                'CodeB',
                                'bla',
                                theme1,
                                view_service_id=1)
    legend3 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend3'},
                                'CodeC',
                                'bla',
                                theme2,
                                view_service_id=1)
    legend4 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend4'},
                                'CodeD',
                                'bla',
                                theme2,
                                view_service_id=1)
    view_service1 = ViewServiceRecord(
        'http://www.test1.url.ch',
        1,
        1.0,
        legend_at_web={'de': 'http://www.test1.url.ch'},
        legends=[legend1, legend2])
    view_service2 = ViewServiceRecord(
        'http://www.test2.url.ch',
        1,
        1.0,
        legend_at_web={'de': 'http://www.test2.url.ch'},
        legends=[legend3, legend4])
    image = ImageRecord('1'.encode('utf-8'))
    plr1 = PlrRecord(
        theme1,
        {'de': 'CONTENT'},
        law_status,
        datetime.datetime.now(),
        office,
        image,
        view_service1,
        geometries,
        type_code='CodeA',
    )
    plr2 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service1,
                     geometries,
                     type_code='CodeB')
    plr3 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code='CodeB')
    plr4 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code='CodeB')

    inside_plrs = [plr1]
    outside_plrs = [plr2, plr3]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(inside_plrs) == len(after_process)
    inside_plrs = [plr3]
    outside_plrs = [plr4]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(after_process) == 1
示例#4
0
def includeme(config):
    """
    By including this in your pyramid web app you can easily provide a running OEREB Server

    Args:
        config (Configurator): The pyramid apps config object
    """

    global route_prefix, app_schema_name, srid

    # Set route prefix
    route_prefix = config.route_prefix

    # Get settings
    settings = config.get_settings()

    # Load configuration file
    cfg_file = settings.get('pyramid_oereb.cfg.file', None)
    cfg_c2ctemplate_file = settings.get('pyramid_oereb.cfg.c2ctemplate.file',
                                        None)
    cfg_section = settings.get('pyramid_oereb.cfg.section', None)
    Config.init(cfg_file or cfg_c2ctemplate_file, cfg_section,
                cfg_file is None)
    Config.update_settings(settings)

    real_estate_config = Config.get_real_estate_config()
    municipality_config = Config.get_municipality_config()
    exclusion_of_liability_config = Config.get_exclusion_of_liability_config()
    glossary_config = Config.get_glossary_config()
    logos = Config.get_logo_config()
    app_schema_name = Config.get('app_schema').get('name')
    srid = Config.get('srid')

    plr_cadastre_authority = Config.get_plr_cadastre_authority()

    real_estate_reader = RealEstateReader(
        real_estate_config.get('source').get('class'),
        **real_estate_config.get('source').get('params'))

    municipality_reader = MunicipalityReader(
        municipality_config.get('source').get('class'),
        **municipality_config.get('source').get('params'))

    exclusion_of_liability_reader = ExclusionOfLiabilityReader(
        exclusion_of_liability_config.get('source').get('class'),
        **exclusion_of_liability_config.get('source').get('params'))

    glossary_reader = GlossaryReader(
        glossary_config.get('source').get('class'),
        **glossary_config.get('source').get('params'))

    plr_sources = []
    for plr in Config.get('plrs'):
        plr_source_class = DottedNameResolver().maybe_resolve(
            plr.get('source').get('class'))
        plr_sources.append(plr_source_class(**plr))

    extract_reader = ExtractReader(plr_sources, plr_cadastre_authority, logos)

    settings.update({
        'pyramid_oereb':
        parse(cfg_file or cfg_c2ctemplate_file, cfg_section, cfg_file is None)
    })
    processor = Processor(
        real_estate_reader=real_estate_reader,
        municipality_reader=municipality_reader,
        exclusion_of_liability_reader=exclusion_of_liability_reader,
        glossary_reader=glossary_reader,
        plr_sources=plr_sources,
        extract_reader=extract_reader,
    )

    def pyramid_oereb_processor(request):
        return processor

    config.add_request_method(pyramid_oereb_processor, reify=True)

    config.add_renderer('pyramid_oereb_extract_json',
                        'pyramid_oereb.lib.renderer.extract.json_.Renderer')
    config.add_renderer('pyramid_oereb_extract_xml',
                        'pyramid_oereb.lib.renderer.extract.xml_.Renderer')
    config.add_renderer('pyramid_oereb_extract_print',
                        Config.get('print').get('renderer'))
    config.add_renderer('pyramid_oereb_versions_xml',
                        'pyramid_oereb.lib.renderer.versions.xml_.Renderer')
    config.add_renderer(
        'pyramid_oereb_capabilities_xml',
        'pyramid_oereb.lib.renderer.capabilities.xml_.Renderer')
    config.add_renderer('pyramid_oereb_getegrid_xml',
                        'pyramid_oereb.lib.renderer.getegrid.xml_.Renderer')

    config.include('pyramid_oereb.routes')
示例#5
0
def test_processor_get_legend_entries(law_status):
    theme1 = ThemeRecord(u'TEST', {'de': 'Theme 1'})
    theme2 = ThemeRecord(u'TEST', {'de': 'Theme 2'})
    office = OfficeRecord({'de': 'Test Office'})
    geometries = [
        GeometryRecord(law_status, datetime.date.today(), Point(1, 1))
    ]
    legend1 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend1'}, u'type1', u'bla', theme1)
    legend2 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend2'}, u'type2', u'bla', theme1)
    legend3 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend3'}, u'type3', u'bla', theme2)
    legend4 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend4'}, u'type4', u'bla', theme2)
    view_service1 = ViewServiceRecord('http://www.test1.url.ch',
                                      'http://www.test1.url.ch',
                                      legends=[legend1, legend2])
    view_service2 = ViewServiceRecord('http://www.test2.url.ch',
                                      'http://www.test2.url.ch',
                                      legends=[legend3, legend4])
    image = ImageRecord('1'.encode('utf-8'))
    plr1 = PlrRecord(
        theme1,
        {'de': 'CONTENT'},
        law_status,
        datetime.datetime.now(),
        office,
        image,
        view_service1,
        geometries,
        type_code=u'type1',
    )
    plr2 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service1,
                     geometries,
                     type_code=u'type2')
    plr3 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code=u'type2')
    plr4 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code=u'type2')

    inside_plrs = [plr1]
    outside_plrs = [plr2, plr3]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(inside_plrs) == len(after_process)
    inside_plrs = [plr3]
    outside_plrs = [plr4]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(after_process) == 1