def test_format_map(params, legend_at_web, expected_legend_at_web): with pyramid_oereb_test_config(): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = params renderer._request = MockRequest() legend_entry = LegendEntryRecord(ImageRecord('1'.encode('utf-8')), {u'de': u'Legendeneintrag'}, u'CodeA', u'type_code_list', ThemeRecord(u'ContaminatedSites', {u'de': u'Test'}), view_service_id=1) view_service = ViewServiceRecord('http://my.wms.ch', 1, 1.0, legend_at_web, [legend_entry]) view_service.image = ImageRecord('1'.encode('utf-8')) result = renderer.format_map(view_service) assert isinstance(result, dict) expected_result = { 'Image': base64.b64encode('1'.encode('utf-8')).decode('ascii'), 'layerIndex': 1, 'layerOpacity': 1.0, 'ReferenceWMS': 'http://my.wms.ch', 'OtherLegend': [renderer.format_legend_entry(legend_entry)] } if expected_legend_at_web is not None: expected_result['LegendAtWeb'] = expected_legend_at_web assert result == expected_result
def test_format_map(config, params): assert isinstance(config._config, dict) with pyramid_oereb_test_config(): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = params renderer._request = MockRequest() legend_entry = LegendEntryRecord( ImageRecord('1'.encode('utf-8')), {u'de': u'Legendeneintrag'}, u'type1', u'type_code_list', ThemeRecord(u'ContaminatedSites', {u'de': u'Test'})) view_service = ViewServiceRecord( 'http://my.wms.ch', 'http://my.wms.ch?SERVICE=WMS&REQUEST=GetLegendGraphic', [legend_entry]) view_service.image = ImageRecord('1'.encode('utf-8')) result = renderer.format_map(view_service) assert isinstance(result, dict) assert result == { 'Image': base64.b64encode('1'.encode('utf-8')).decode('ascii'), 'ReferenceWMS': 'http://my.wms.ch', 'LegendAtWeb': 'http://my.wms.ch?SERVICE=WMS&REQUEST=GetLegendGraphic', 'OtherLegend': [renderer.format_legend_entry(legend_entry)] }
def test_format_legend_entry(parameter, config): assert isinstance(config._config, dict) with pyramid_oereb_test_config(): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = parameter renderer._request = MockRequest() theme = ThemeRecord(u'ContaminatedSites', {u'de': u'Test'}) legend_entry = LegendEntryRecord(ImageRecord('1'.encode('utf-8')), {u'de': u'Legendeneintrag'}, u'type1', u'type_code_list', theme, u'Subthema', u'Weiteres Thema') result = renderer.format_legend_entry(legend_entry) expected = { 'LegendText': renderer.get_multilingual_text({'de': 'Legendeneintrag'}), 'TypeCode': 'type1', 'TypeCodelist': 'type_code_list', 'Theme': renderer.format_theme(theme), 'SubTheme': 'Subthema', 'OtherTheme': 'Weiteres Thema' } if parameter.images: expected.update( {'Symbol': ImageRecord('1'.encode('utf-8')).encode()}) else: expected.update({ 'SymbolRef': 'http://example.com/image/symbol/{theme_code}/{code}'.format( theme_code='ContaminatedSites', code='type1') }) assert isinstance(result, dict) assert result == expected
def test_format_legend_entry(parameter): with pyramid_oereb_test_config(): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = parameter renderer._request = MockRequest() theme = ThemeRecord(u'ContaminatedSites', {u'de': u'Test'}) legend_entry = LegendEntryRecord( ImageRecord(FileAdapter().read('tests/resources/python.svg')), {u'de': u'Legendeneintrag'}, u'CodeA', u'type_code_list', theme, {'de': u'Subthema'}, u'Weiteres Thema', view_service_id=1 ) result = renderer.format_legend_entry(legend_entry) expected = { 'LegendText': renderer.get_multilingual_text({'de': 'Legendeneintrag'}), 'TypeCode': 'CodeA', 'TypeCodelist': 'type_code_list', 'Theme': renderer.format_theme(theme), 'SubTheme': 'Subthema', 'OtherTheme': 'Weiteres Thema' } if parameter.images: expected.update({ 'Symbol': ImageRecord(FileAdapter().read('tests/resources/python.svg')).encode() }) else: expected.update({ 'SymbolRef': 'http://example.com/image/symbol/{theme_code}/{view_service_id}/{code}.svg' .format( theme_code='ContaminatedSites', view_service_id=1, code='CodeA' ) }) assert isinstance(result, dict) assert result == expected