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_get_document_type(): document = DocumentRecord(LawStatusRecord.from_config('inForce'), datetime.date.today(), {'de': 'Test'}, OfficeRecord({'de': 'Test'})) legal_provision = LegalProvisionRecord( LawStatusRecord.from_config('inForce'), datetime.date.today(), {'de': 'Test'}, OfficeRecord({'de': 'Test'})) assert Renderer._get_document_type(document) == 'data:Document' assert Renderer._get_document_type( legal_provision) == 'data:LegalProvisions'
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 = BytesIO(rendered) doc = etree.parse(buffer) xmlschema.assertValid(doc)
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_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 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_get_gml_id(): renderer = Renderer(None) assert renderer._get_gml_id() == 'gml1' assert renderer._get_gml_id() == 'gml2' assert renderer._get_gml_id() == 'gml3'