def test_read(): reader = GlossaryReader( Config.get_glossary_config().get('source').get('class'), **Config.get_glossary_config().get('source').get('params')) results = reader.read() assert isinstance(results, list) assert len(results) == 1
def __init__(self, configuration, section='pyramid_oereb', c2ctemplate_style=False, directory='sample_data', sql_file=None): """ Args: configuration (str): Path to the configuration yaml file. section (str): The used section within the yaml file. Default is `pyramid_oereb`. c2ctemplate_style (bool): True if the yaml use a c2c template style (vars.[section]). Default is False. directory (str): Location of the sample data. Default is `sample_data`. sql_file (file): The SQL file to be created. Default is None. """ self._configuration = configuration self._section = section self._directory = directory self._sql_file = sql_file Config.init(self._configuration, self._section, c2ctemplate_style) self._engine = create_engine( Config.get('app_schema').get('db_connection'), echo=True) self._connection = None
def test_get_custom_wms_params_true(): Config._config = None Config.init('./tests/contrib/print_proxy/resources/test_custom_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) # Define different test cases params1 = { 'TRANSPARENT': ['true'], 'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31'] } params2 = {'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31']} params3 = {'epoch': '2018-11-29T15:13:31'} params4 = {'epoch': ['2018-11-29T15:13:31', '2020-11-29T17:13:50']} config1 = renderer.get_custom_wms_params(params1) config2 = renderer.get_custom_wms_params(params2) config3 = renderer.get_custom_wms_params(params3) config4 = renderer.get_custom_wms_params(params4) # Restore normal config Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') # Do the check for the different test cases. Value should match the ones from the YAML configuration. assert config1 == {'TRANSPARENT': 'true', 'epoch': '2018-11-29T15:13:31'} assert config2 == {'epoch': '2018-11-29T15:13:31'} assert config3 == {'epoch': '2018-11-29T15:13:31'} assert config4 == {'epoch': '2018-11-29T15:13:31,2020-11-29T17:13:50'}
def test_get_all_federal(): Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') all_federal = Config.get_all_federal() assert isinstance(all_federal, list) assert len(all_federal) == 10 assert 'RailwaysProjectPlanningZones' in all_federal
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() assert isinstance(results, list) assert len(results) == 0
def test_get_base_data(): Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') date = datetime.datetime(2017, 2, 1) base_data = Config.get_base_data(date) assert isinstance(base_data, dict) assert base_data.get( 'de') == 'Daten der amtlichen Vermessung, Stand 01.02.2017.'
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'))
def test_get_real_estate_main_page_config(): Config._config = None Config.init('./tests/resources/test_config.yml', 'pyramid_oereb') plan_for_land_register_main_page_config = Config.get_plan_for_land_register_main_page_config( ) assert plan_for_land_register_main_page_config.get('reference_wms') == 'https://wms.ch/?BBOX=2475000,' \ '1065000,2850000,1300000' assert plan_for_land_register_main_page_config.get('layer_index') == 2 assert plan_for_land_register_main_page_config.get('layer_opacity') == 0.5
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(**param) assert len(records) == 1 record = records[0] assert isinstance(record, RealEstateRecord) assert record.fosnr == 1234
def test_get_layer_config(): Config._config = None Config.init('./tests/resources/test_config.yml', 'pyramid_oereb') layer_index, layer_opacity = Config.get_layer_config('LandUsePlans') assert layer_index == 1 assert layer_opacity == 0.25 layer_index, layer_opacity = Config.get_layer_config( 'MotorwaysProjectPlaningZones') assert layer_index is None assert layer_opacity is None
def test_config_wms_url_params(): Config._config = None Config.init('./tests/contrib/print_proxy/resources/test_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) config = renderer.get_wms_url_params() # Restore normal config Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') # Do the check for this test. Value should match the one from the YAML configuration. assert config == {'TRANSPARENT': 'true', 'OTHERCUSTOM': 'myvalue'}
def test_read(): reader = GlossaryReader( Config.get_glossary_config().get('source').get('class'), **Config.get_glossary_config().get('source').get('params')) results = reader.read() 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']
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(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
def test_bad_config_wms_url_params(): Config._config = None Config.init('./tests/contrib/print_proxy/resources/test_bad_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) config = renderer.get_wms_url_params() # Restore normal config Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') # Do the check for this test. Value should be empty. assert config == {}
def process(self, real_estate, params, sld_url): """ Central processing method to hook in from webservice. Args: real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate reader to obtain the real estates record. params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. sld_url (str): The URL which provides the sld to style and filter the highlight of the real estate. Returns: pyramid_oereb.lib.records.extract.ExtractRecord: The generated extract record. """ log.debug("process() start") municipality = self._municipality_reader_.read(params, real_estate.fosnr)[0] exclusions_of_liability = self._exclusion_of_liability_reader_.read( params) glossaries = self._glossary_reader_.read(params) extract_raw = self._extract_reader_.read(params, real_estate, municipality) extract = self.plr_tolerance_check(extract_raw) resolver = DottedNameResolver() sort_within_themes_method_string = Config.get('extract').get( 'sort_within_themes_method') if sort_within_themes_method_string: sort_within_themes_method = resolver.resolve( sort_within_themes_method_string) extract = sort_within_themes_method(extract) else: log.info( "No configuration is provided for extract sort_within_themes_method;" " no further sorting is applied.") # the selection of view services is done after the tolerance check. This enables us to take # care about the circumstance that after tolerance check plrs will be dismissed which were # recognized as intersecting before. To avoid this the tolerance check is gathering all plrs # intersecting and not intersecting and starts the legend entry sorting after. self.view_service_handling(extract.real_estate, params.images, params.format) extract.exclusions_of_liability = exclusions_of_liability extract.glossaries = glossaries # obtain the highlight wms url and its content only if the parameter full was requested (PDF) if params.flavour == 'full': if Config.get('full_extract_use_sld', True): extract.real_estate.set_highlight_url(sld_url) log.debug("process() done, returning extract.") return extract
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, )
def test_get_oereblex_config(): Config._config = None Config.init('./tests/resources/test_config.yml', 'pyramid_oereb') cfg = Config.get_oereblex_config() assert isinstance(cfg, dict) assert cfg == { 'host': 'http://oereblex.example.com', 'language': 'de', 'proxy': { 'http': 'http://my.proxy.org', 'https': None } }
def test_read(): reader = MunicipalityReader( Config.get_municipality_config().get('source').get('class'), **Config.get_municipality_config().get('source').get('params')) results = reader.read() 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)))'
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() 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']
def __init__(self, configuration_file, topic_code, section='pyramid_oereb', c2ctemplate_style=False, arc_max_diff=0.001, arc_precision=3, tmp_dir='.', srid=None): """ Args: configuration_file (str): Path to the configuration file to be used. topic_code (str): The code of the federal topic to be updated. section (str): The section within the configuration file. (default: 'pyramid_oereb') c2ctemplate_style (bool): True if the yaml use a c2c template style (vars.[section]). Default is False. arc_max_diff (float): Maximum difference between arc and line segment for stroking. (default: 0.001) arc_precision (int): Coordinate precision for generated arc points. (default: 3) tmp_dir (str): Directory used as temporary working directory. (default: '.') """ self._log = logging.getLogger('import_federal_topic') Config.init(configuration_file, section, c2ctemplate_style) self._settings = Config.get_config() topic_settings = None for topic in self._settings.get('plrs'): if topic.get('code') == topic_code: topic_settings = topic if topic_settings is None: self._log.error('Cannot find topic {0} in {1}'.format( topic_code, configuration_file)) exit(1) self._srid = srid or self._settings.get('srid') if self._srid is None: self._log.error( 'No SRID defined in configuration or passed as argument') exit(1) self._tmp_dir = tmp_dir self._arc_max_diff = arc_max_diff self._arc_precision = arc_precision self._topic_settings = topic_settings self._connection = topic_settings.get('source').get('params').get( 'db_connection') models_path = topic_settings.get('source').get('params').get('models') self._models = DottedNameResolver().maybe_resolve(models_path) self._file_id = '{0}'.format(uuid4()) self._checksum = None self._data_integration_office_id = None
def calculate(self, real_estate, min_length, min_area, length_unit, area_unit): """ Entry method for calculation. It checks if the geometry type of this instance is a geometry collection which has to be unpacked first in case of collection. Args: real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate record. min_length (float): The threshold to consider or not a line element. min_area (float): The threshold to consider or not a surface element. length_unit (unicode): The thresholds unit for area calculation. area_unit (unicode): The thresholds unit for area calculation. Returns: bool: True if intersection fits the limits. """ geometry_types = Config.get('geometry_types') line_types = geometry_types.get('line').get('types') polygon_types = geometry_types.get('polygon').get('types') point_types = geometry_types.get('point').get('types') if self.published: result = self._extract_collection( self.geom.intersection(real_estate.limit)) # TODO upon update to Shapely 1.7, a check for result.is_emtpy will be needed (see PR#1037) # differentiate between Points and MultiPoint if self.geom.type not in point_types + line_types + polygon_types: supported_types = ', '.join(point_types + line_types + polygon_types) raise AttributeError( u'The passed geometry is not supported: {type}. It should be one of: {types}' .format(type=self.geom.type, types=supported_types)) elif self.geom.type in point_types: if result.type == point_types[1]: # If it is a multipoint make a list and count the number of elements in the list self._nr_of_points = len(list(result.geoms)) self._test_passed = True elif result.type == point_types[0]: # If it is a single point the number of points is one self._nr_of_points = 1 self._test_passed = True elif self.geom.type in line_types and result.type in line_types: self._units = length_unit length_share = result.length if length_share >= min_length: self._length_share = length_share self._test_passed = True elif self.geom.type in polygon_types and result.type in polygon_types: self._units = area_unit area_share = result.area compensated_area = area_share / real_estate.areas_ratio if compensated_area >= min_area: self._area_share = compensated_area self._test_passed = True else: log.debug( u'Intersection result changed geometry type. ' u'Original geometry was {0} and result is {1}'.format( self.geom.type, result.type)) self.calculated = True return self._test_passed
def test_add_existing_connection(): db_url = Config.get('app_schema').get('db_connection') adapter = DatabaseAdapter() adapter.add_connection(db_url) expected_length = len(adapter.get_connections()) adapter.add_connection(db_url) assert len(adapter.get_connections()) == expected_length
def get_full_wms_url(self, real_estate, format): """ Returns the WMS URL to get the image. Args: real_estate (pyramid_oereb.lob.records.real_estate.RealEstateRecord): The Real Estate record. format (string): The format currently used. For 'pdf' format, the used map size will be adapted to the pdf format, Returns: str: The url used to query the WMS server. """ assert real_estate.limit is not None map_size = self.get_map_size(format) bbox = self.get_bbox(real_estate.limit) self.reference_wms = add_url_params( self.reference_wms, { "BBOX": ",".join([str(e) for e in bbox]), "SRS": 'EPSG:{0}'.format(Config.get('srid')), "WIDTH": int(map_size[0]), "HEIGHT": int(map_size[1]) }) self.calculate_ns() return self.reference_wms
def parse(self, view_service): # pragma: no cover language = Config.get('default_language') for element in view_service: if get_tag(element) == self.TAG_LEGEND: count = 1 for legend_entry in element: if get_tag(legend_entry) == self.TAG_LEGEND_ENTRY: sub_theme = parse_string(legend_entry, self.TAG_SUB_THEME) if sub_theme is not None: sub_theme = {language: sub_theme} instance = self._model( id='{0}.legende.{1}'.format( view_service.attrib['TID'], count), symbol=self._parse_symbol(legend_entry, self.TAG_SYMBOL), legend_text=parse_multilingual_text( legend_entry, self.TAG_LEGEND_TEXT), type_code=parse_string(legend_entry, self.TAG_TYPE_CODE), type_code_list=parse_string( legend_entry, self.TAG_TYPE_CODE_LIST), topic=self._topic_code, sub_theme=sub_theme, other_theme=parse_string(legend_entry, self.TAG_OTHER_THEME), view_service_id=view_service.attrib['TID']) self._session.add(instance) count += 1
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
def parse(self, public_law_restriction): # pragma: no cover language = Config.get('default_language') sub_theme = parse_string(public_law_restriction, self.TAG_SUB_THEME) if sub_theme is not None: sub_theme = {language: sub_theme} instance = self._model( id=public_law_restriction.attrib['TID'], information=parse_multilingual_text(public_law_restriction, self.TAG_INFORMATION), topic=self._topic_code, sub_theme=sub_theme, other_theme=parse_string(public_law_restriction, self.TAG_OTHER_THEME), type_code=parse_string(public_law_restriction, self.TAG_TYPE_CODE), type_code_list=parse_string(public_law_restriction, self.TAG_TYPE_CODE_LIST), law_status=parse_string(public_law_restriction, self.TAG_LAW_STATUS), published_from=parse_string(public_law_restriction, self.TAG_PUBLISHED_FROM), view_service_id=parse_ref(public_law_restriction, self.TAG_VIEW_SERVICE), office_id=parse_ref(public_law_restriction, self.TAG_RESPONSIBLE_OFFICE)) self._session.add(instance)
def test_read(param): source = DatabaseSource( **Config.get_real_estate_config().get('source').get('params')) source.read(**param) assert len(source.records) == 1 record = source.records[0] assert isinstance(record, RealEstateRecord) assert record.fosnr == 1234
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 calculate_ns(self): srid = Config.get_crs() if srid == u'epsg:2056': self.min_NS95, self.max_NS95 = self.get_bbox_from_url( self.reference_wms) if srid == u'epsg:21781': self.min_NS03, self.max_NS03 = self.get_bbox_from_url( self.reference_wms)
def test_get_custom_wms_params_false(): Config._config = None Config.init('./tests/contrib/print_proxy/resources/test_config.yml', 'pyramid_oereb') renderer = Renderer(DummyRenderInfo()) params = { 'TRANSPARENT': ['true'], 'OTHERCUSTOM': ['myvalue'], 'epoch': ['2018-11-29T15:13:31'] } config = renderer.get_custom_wms_params(params) # Restore normal config Config._config = None Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb') assert config == {'OTHERCUSTOM': 'myvalue', 'TRANSPARENT': 'true'}