def test_sub_theme(): parameters = Parameter( response_format='xml', flavour='reduced', with_geometry=False, images=True, identdn='BL0200002829', number='1000', egrid='CH775979211712', language='de') renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._request = MockRequest() renderer._request.route_url = lambda url, **kwargs: "http://example.com/current/view" legend_entry = LegendEntryRecord( symbol=ImageRecord('1'.encode('utf-8')), legend_text={'de': 'legend1'}, type_code='LandUsePlans', type_code_list='bla', theme=ThemeRecord(u'LandUsePlans', {'de': 'Theme 1'}), sub_theme={'de': 'sub theme de'} ) content = template.render(**{ 'params': parameters, 'localized': renderer.get_localized_text, 'multilingual': renderer.get_multilingual_text, 'legend_entry': legend_entry }).decode('utf-8').split('\n') no_empty_lines = list(filter(lambda line: line != '', content)) assert no_empty_lines[19] == '<data:SubTheme>sub theme de</data:SubTheme>' assert len(no_empty_lines) == 20
def test_legend_at_web_no_language(): # Requests italian, but only german is available -> best effort: deliver german instead parameters = Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'it') renderer = Renderer(None) legend_url = """ http://example.com? SERVICE=WMS& REQUEST=GetLegendGraphic& FORMAT=image/png& SRS=epsg:2056 """.replace(" ", "").replace('\n', '') map = ViewServiceRecord(reference_wms='', legend_at_web={'de': legend_url}, layer_index=0, layer_opacity=1.0) content = template.render(**{ 'params': parameters, 'localized': renderer.get_localized_text, 'map': map }).decode('utf-8').split('\n') assert len(content) == 6 assert content[2] == """ <data:LegendAtWeb> http%3A%2F%2Fexample.com%3F SERVICE%3DWMS%26 REQUEST%3DGetLegendGraphic%26 FORMAT%3Dimage%2Fpng%26 SRS%3Depsg%3A2056 </data:LegendAtWeb> """.replace(" ", "").replace('\n', '')
def test_format_real_estate(config): assert isinstance(config._config, dict) renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = Parameter( 'reduced', 'json', True, False, 'BL0200002829', '1000', 'CH775979211712', 'de') geometry = MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]) view_service = ViewServiceRecord(u'http://geowms.bl.ch', u'http://geowms.bl.ch') document = DocumentRecord(law_status(), datetime.date.today(), {u'de': u'Test Dokument'}, OfficeRecord({u'de': u'BUD'}), {'de': 'http://mein.dokument.ch'}) real_estate = RealEstateRecord(u'RealEstate', u'BL', u'Liestal', 2829, 11395, geometry, u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712', u'Subunit', [], references=[document]) real_estate.plan_for_land_register = view_service result = renderer.format_real_estate(real_estate) assert isinstance(result, dict) assert result == { 'Type': u'RealEstate', 'Canton': u'BL', 'Municipality': u'Liestal', 'FosNr': 2829, 'LandRegistryArea': 11395, 'PlanForLandRegister': renderer.format_map(view_service), 'Limit': renderer.from_shapely(geometry), 'Number': u'1000', 'IdentDN': u'BL0200002829', 'EGRID': u'CH775979211712', 'SubunitOfLandRegister': u'Subunit', 'MetadataOfGeographicalBaseData': u'http://www.geocat.ch', 'Reference': [renderer.format_document(document)] }
def test_legend_at_web(): parameters = Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de') renderer = Renderer(None) map = ViewServiceRecord(reference_wms='', legend_at_web={'de': 'http://example-legend.com'}, layer_index=0, layer_opacity=1.0) content = template.render(**{ 'params': parameters, 'localized': renderer.get_localized_text, 'map': map }).decode('utf-8').split('\n') assert len(content) == 6 assert content[ 2] == '<data:LegendAtWeb>http%3A%2F%2Fexample-legend.com</data:LegendAtWeb>'
def test_legend_at_web_no_language(): # Requests italian, but only german is available -> best effort: deliver german instead parameters = Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'it') renderer = Renderer(None) map = ViewServiceRecord(reference_wms='', legend_at_web={'de': 'http://example-legend.com'}, layer_index=0, layer_opacity=1.0) content = template.render(**{ 'params': parameters, 'localized': renderer.get_localized_text, 'map': map }).decode('utf-8').split('\n') assert len(content) == 6 assert content[ 2] == '<data:LegendAtWeb>http%3A%2F%2Fexample-legend.com</data:LegendAtWeb>'
def test_sub_theme(): parameters = Parameter(flavour='reduced', format='xml', geometry=False, images=True, identdn='BL0200002829', number='1000', egrid='CH775979211712', language='de') renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._request = MockRequest() renderer._request.route_url = lambda url, **kwargs: "http://example.com/current/view" office = OfficeRecord(name={'de': 'office de'}) law_status = LawStatusRecord(code='runningModifications', text={'de': 'law status de'}) geometry = GeometryRecord(law_status, datetime.now(), Polygon(), 'test', office=office) public_law_restriction = PlrRecord( theme=ThemeRecord(u'LandUsePlans', {'de': 'Theme 1'}), information={'de': 'information de'}, law_status=law_status, published_from=datetime.now(), responsible_office=office, symbol=ImageRecord('1'.encode('utf-8')), view_service=ViewServiceRecord(reference_wms='', layer_index=0, layer_opacity=1.0), geometries=[geometry], sub_theme={'de': 'sub theme de'}) content = template.render( **{ 'params': parameters, 'localized': renderer.get_localized_text, 'multilingual': renderer.get_multilingual_text, 'public_law_restriction': public_law_restriction }).decode('utf-8').split('\n') no_empty_lines = list(filter(lambda line: line != '', content)) assert no_empty_lines[ 18] == ' <data:SubTheme>sub theme de</data:SubTheme>' assert len(no_empty_lines) == 72
def default_param(): return Parameter('reduced', 'json', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de')
return [{ 'Title': [{ 'Language': 'de', 'Text': 'Glossar' }], 'Content': [{ 'Language': 'de', 'Text': 'Test' }] }] @pytest.mark.parametrize('parameter, glossaries_input, glossaries_expected', [ (default_param(), glossary_input(), glossary_expected()), (default_param(), [], []), (Parameter('reduced', 'json', False, True, 'BL0200002829', '1000', 'CH775979211712', 'de'), glossary_input(), glossary_expected()), (None, glossary_input(), glossary_expected()), (None, [], None), (None, None, None) ]) def test_render(parameter, glossaries_input, glossaries_expected): date = datetime.datetime.now() with pyramid_oereb_test_config(): view_service = ViewServiceRecord(u'http://geowms.bl.ch', 1, 1.0, {'de': u'http://geowms.bl.ch'}, None) real_estate = RealEstateRecord( u'RealEstate', u'BL', u'Liestal', 2829, 11395, MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]), u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712') real_estate.set_view_service(view_service) real_estate.set_main_page_view_service(view_service)
} } renderer = VersionsRenderer(DummyRenderInfo()) rendered = renderer._render(versions) xmlschema_doc = etree.parse(schema_xml_versions) xmlschema = etree.XMLSchema(xmlschema_doc) buffer = StringIO(rendered) if sys.version_info.major == 2 else BytesIO( rendered) doc = etree.parse(buffer) assert xmlschema.validate(doc) @pytest.mark.parametrize( 'parameter, test_extract', [(Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de'), get_default_extract()), (Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de'), get_empty_glossary_extract()), (Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de'), get_none_glossary_extract())]) def test_extract_against_schema(parameter, test_extract): extract = test_extract renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._request = MockRequest() renderer._request.route_url = lambda url, **kwargs: "http://example.com/current/view" rendered = renderer._render(extract, parameter) xmlschema_doc = etree.parse(schema_xml_extract) xmlschema = etree.XMLSchema(xmlschema_doc) buffer = StringIO(rendered) if sys.version_info.major == 2 else BytesIO(
def test_parameter(): params = Parameter('reduced', 'json', True, False) params.set_identdn('identdn') params.set_number('1000') params.set_egrid('EGRID') params.set_language('de') params.set_topics(['topic1', 'topic2']) assert params.flavour == 'reduced' assert params.format == 'json' assert params.with_geometry assert not params.images assert params.identdn == 'identdn' assert params.number == '1000' assert params.egrid == 'EGRID' assert params.language == 'de' assert params.topics == ['topic1', 'topic2']
from pyramid_oereb.views.webservice import Parameter def law_status(): return LawStatusRecord(u'inForce', {'de': u'In Kraft'}) @pytest.fixture() def params(): return Parameter('reduced', 'json', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de') @pytest.mark.parametrize('parameter', [ params(), Parameter('reduced', 'json', False, True, 'BL0200002829', '1000', 'CH775979211712', 'de'), None ]) def test_render(config, parameter): date = datetime.datetime.now() assert isinstance(config._config, dict) with pyramid_oereb_test_config(): view_service = ViewServiceRecord(u'http://geowms.bl.ch', u'http://geowms.bl.ch') real_estate = RealEstateRecord( u'RealEstate', u'BL', u'Liestal', 2829, 11395, MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]), u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712') real_estate.plan_for_land_register = view_service office_record = OfficeRecord({'de': u'AGI'}) resolver = DottedNameResolver()
} ] } } renderer = VersionsRenderer(DummyRenderInfo()) rendered = renderer._render(versions) xmlschema_doc = etree.parse(schema_xml_versions) xmlschema = etree.XMLSchema(xmlschema_doc) buffer = StringIO(rendered) if sys.version_info.major == 2 else BytesIO(rendered) doc = etree.parse(buffer) assert xmlschema.validate(doc) @pytest.mark.parametrize('parameter', [ Parameter('reduced', 'xml', False, False, 'BL0200002829', '1000', 'CH775979211712', 'de') ]) def test_extract_against_schema(parameter): extract = get_test_extract() renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._request = MockRequest() renderer._request.route_url = lambda url, **kwargs: "http://example.com/current/view" rendered = renderer._render(extract, parameter) xmlschema_doc = etree.parse(schema_xml_extract) xmlschema = etree.XMLSchema(xmlschema_doc) buffer = StringIO(rendered) if sys.version_info.major == 2 else BytesIO(rendered) doc = etree.parse(buffer) xmlschema.assertValid(doc)