Exemplo n.º 1
0
def test_get_image():
    request = MockRequest()
    request.matchdict.update({'logo': 'oereb'})
    webservice = Logo(request)
    result = webservice.get_image()
    assert isinstance(result, Response)
    assert result.body == Config.get_logo_config().get('oereb').content
Exemplo n.º 2
0
def test_get_logo_config():
    Config._config = None
    Config.init('./tests/resources/test_config.yml', 'pyramid_oereb')
    logos = Config.get_logo_config()
    assert isinstance(logos, dict)
    logo_oereb = logos.get('oereb')
    assert isinstance(logo_oereb, ImageRecord)
    assert logo_oereb.content == FileAdapter().read(
        Config.get('logo').get('oereb'))
Exemplo n.º 3
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,
    )
Exemplo n.º 4
0
    def __init__(self, current_route_url=None):
        super(MockRequest, self).__init__()

        self._current_route_url = current_route_url

        Config._config = None
        Config.init(pyramid_oereb_test_yml, 'pyramid_oereb')

        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)
        self.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,
        )
Exemplo n.º 5
0
def test_get_logo_multilingual(language):
    Config._config = None
    Config.init('./tests/resources/test_config.yml', 'pyramid_oereb')
    Config.get('logo')['oereb'] = {
        'de': 'pyramid_oereb/standard/logo_oereb_de.png',
        'fr': 'pyramid_oereb/standard/logo_oereb_fr.png',
        'it': 'pyramid_oereb/standard/logo_oereb_it.png'
    }
    logos = Config.get_logo_config(language=language)
    assert isinstance(logos, dict)
    logo_oereb = logos.get('oereb')
    if language is None:
        assert logo_oereb.content == FileAdapter().read(
            Config.get('logo').get('oereb').get('de'))
    else:
        assert logo_oereb.content == FileAdapter().read(
            Config.get('logo').get('oereb').get(language))
Exemplo n.º 6
0
    def read(self, params, real_estate, municipality):
        """
        This method finally creates the extract.

        .. note:: If you subclass this class your implementation needs to offer this method in the same
            signature. Means the parameters must be the same and the return must be a
            :ref:`api-pyramid_oereb-lib-records-extract-extractrecord`. Otherwise the API like way the server
            works would be broken.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request.
            real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real
                estate for which the report should be generated
            municipality (pyramid_oereb.lib.records.municipiality.MunicipalityRecord): The municipality
                record.

        Returns:
            pyramid_oereb.lib.records.extract.ExtractRecord:
                The extract record containing all gathered data.
        """
        log.debug("read() start")
        assert isinstance(municipality.logo, ImageRecord)

        bbox = ViewServiceRecord.get_bbox(real_estate.limit)
        bbox = box(bbox[0], bbox[1], bbox[2], bbox[3])

        datasource = list()
        concerned_themes = list()
        not_concerned_themes = list()
        themes_without_data = list()

        if municipality.published:

            for position, plr_source in enumerate(self._plr_sources_, start=1):
                if not params.skip_topic(plr_source.info.get('code')):
                    log.debug("read() going to read from plr_source {}".format(plr_source))
                    plr_source.read(params, real_estate, bbox, position)
                    log.debug("read() done reading from plr_source {}".format(plr_source))
                    for ds in plr_source.datasource:
                        if not params.skip_topic(ds.theme.code):
                            datasource.append(ds)
                    real_estate.public_law_restrictions.extend(plr_source.records)

            for plr in real_estate.public_law_restrictions:

                # Filter topics due to topics parameter
                if not params.skip_topic(plr.theme.code):
                    if isinstance(plr, PlrRecord):
                        contained = False
                        for theme in concerned_themes:
                            if theme.code == plr.theme.code:
                                contained = True
                        if not contained:
                            concerned_themes.append(plr.theme)
                    elif isinstance(plr, EmptyPlrRecord):
                        if plr.has_data:
                            not_concerned_themes.append(plr.theme)
                        else:
                            themes_without_data.append(plr.theme)

        else:
            for plr_source in self._plr_sources_:
                themes_without_data.append(Config.get_theme(plr_source.info.get('code')))

        # Load base data form configuration
        resolver = DottedNameResolver()
        date_method_string = Config.get('extract').get('base_data').get('methods').get('date')
        date_method = resolver.resolve(date_method_string)
        av_update_date = date_method(real_estate)
        base_data = Config.get_base_data(av_update_date)
        general_information = Config.get('extract').get('general_information')
        logos = Config.get_logo_config(language=params.language)

        av_provider_method_string = Config.get('extract').get('base_data').get('methods').get('provider')
        av_provider_method = resolver.resolve(av_provider_method_string)
        cadaster_state = datetime.datetime.now()
        embeddable = EmbeddableRecord(
            cadaster_state,
            self.plr_cadastre_authority,
            av_provider_method(real_estate),
            av_update_date,
            datasource
        )

        self.extract = ExtractRecord(
            real_estate,
            logos.get('oereb'),
            logos.get('confederation'),
            logos.get('canton'),
            municipality.logo,
            self.plr_cadastre_authority,
            base_data,
            embeddable,
            self.certification,
            self.certification_at_web,
            concerned_theme=concerned_themes,
            not_concerned_theme=not_concerned_themes,
            theme_without_data=themes_without_data,
            general_information=general_information
        )

        log.debug("read() done")
        return self.extract
Exemplo n.º 7
0
def test_get_logos_config():
    Config._config = None
    Config.init('./tests/resources/test_config.yml', 'pyramid_oereb')
    logos = Config.get_logo_config()
    assert isinstance(logos, dict)
Exemplo n.º 8
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')