예제 #1
0
from tests.renderer import DummyRenderInfo
from tests.renderer.xml import xml_templates
from pyramid_oereb.lib.records.image import ImageRecord
from pyramid_oereb.lib.records.theme import ThemeRecord
from pyramid_oereb.lib.records.view_service import LegendEntryRecord
from pyramid_oereb.lib.renderer.extract.xml_ import Renderer
from pyramid_oereb.views.webservice import Parameter
from tests.mockrequest import MockRequest

template = xml_templates().get_template('legend_entry.xml')


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',
# -*- coding: utf-8 -*-

import pytest
from tests import params
from tests.renderer.xml import xml_templates
from shapely.geometry import Polygon

template = xml_templates().get_template('geometry/polygon.xml')


@pytest.mark.parametrize('parameters', params)  # noqa
def test_polygon(parameters):
    polygon = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)),
                      [((0.25, 0.25), (0.25, 0.75), (0.75, 0.75), (0.75, 0.25),
                        (0.25, 0.25))])

    def get_gml_id():
        return 'gml1'

    content = template.render(
        **{
            'params': parameters,
            'default_language': 'de',
            'polygon': polygon,
            'get_gml_id': get_gml_id
        }).decode('utf-8').split('\n')
    expected_content = """

    <gml:Polygon gml:id="gml1">
        <gml:exterior>
            <gml:LinearRing>
# -*- coding: utf-8 -*-

from tests.renderer.xml import xml_templates
from pyramid_oereb.lib.records.view_service import ViewServiceRecord
from pyramid_oereb.views.webservice import Parameter
from pyramid_oereb.lib.renderer.extract.xml_ import Renderer

template = xml_templates().get_template('view_service.xml')


def test_empty():
    map = ViewServiceRecord(reference_wms='', layer_index=0, layer_opacity=1.0)
    content = template.render(**{'map': map}).decode('utf-8').split('\n')
    assert content[0] == ''  # empty filler line
    assert content[1] == '<data:layerIndex>0</data:layerIndex>'
    assert content[2] == '<data:layerOpacity>1.0</data:layerOpacity>'
    assert content[3] == ''  # empty filler line
    assert len(content) == 4


def test_reference_wms():
    map = ViewServiceRecord(
        reference_wms=
        'http://example.com?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&SRS=epsg:2056',
        layer_index=0,
        layer_opacity=1.0)
    content = template.render(**{'map': map}).decode('utf-8').split('\n')
    assert content[1] == """
    <data:ReferenceWMS>
    http%3A%2F%2Fexample.com%3F
    SERVICE%3DWMS%26
# -*- coding: utf-8 -*-

import pytest
from tests import params
from tests.renderer.xml import xml_templates
from shapely.geometry import LineString

template = xml_templates().get_template('geometry/line.xml')


@pytest.mark.parametrize('parameters', params)  # noqa
def test_line(parameters):
    line = LineString(((0, 0), (1, 1)))

    def get_gml_id():
        return 'gml1'

    content = template.render(
        **{
            'params': parameters,
            'default_language': 'de',
            'line': line,
            'get_gml_id': get_gml_id
        }).decode('utf-8').split('\n')
    expected_content = """

    <gml:LineString gml:id="gml1">
        <gml:posList>
            0.0 0.0 1.0 1.0
        </gml:posList>
    </gml:LineString>
from pyramid_oereb.lib.records.geometry import GeometryRecord
from pyramid_oereb.lib.records.image import ImageRecord
from pyramid_oereb.lib.records.law_status import LawStatusRecord
from pyramid_oereb.lib.records.office import OfficeRecord
from pyramid_oereb.lib.records.plr import PlrRecord
from pyramid_oereb.lib.records.theme import ThemeRecord
from pyramid_oereb.lib.records.view_service import ViewServiceRecord
from pyramid_oereb.lib.renderer.extract.xml_ import Renderer
from pyramid_oereb.views.webservice import Parameter
from tests.mockrequest import MockRequest
from tests.renderer import DummyRenderInfo
from tests.renderer.xml import xml_templates
from datetime import datetime
from shapely.geometry import Polygon

template = xml_templates().get_template('public_law_restriction.xml')


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"
# -*- coding: utf-8 -*-

import pytest
from tests import params
from tests.renderer.xml import xml_templates
from shapely.geometry import Point

template = xml_templates().get_template('geometry/point.xml')


@pytest.mark.parametrize('parameters', params)  # noqa
def test_point(parameters):
    point = Point((0, 0))
    content = template.render(**{
        'params': parameters,
        'default_language': 'de',
        'point': point
    }).decode('utf-8').split('\n')
    expected_content = """
    <gml:pos>0.0 0.0</gml:pos>""".split('\n')
    expected_lines = []
    for line in expected_content:
        expected_lines.append(line.strip())
    content_lines = []
    for line in content:
        content_lines.append(line.strip())
    assert expected_lines == content_lines