def test_invalid_layer_index_arguments(pyramid_oereb_test_config):
    with pytest.raises(AttributeError):
        ViewServiceRecord({'de': 'http://example.com'}, -1001, 1, 'de', 2056,
                          None, None)
    with pytest.raises(AttributeError):
        ViewServiceRecord({'de': 'http://example.com'}, 1001, 1, 'de', 2056,
                          None, None)
    with pytest.warns(UserWarning,
                      match='Type of "layer_index" should be "int"'):
        ViewServiceRecord({'de': 'http://example.com'}, 1.0, 1, 'de', 2056,
                          None, None)
def test_invalid_layer_layer_opacity(pyramid_oereb_test_config):
    with pytest.raises(AttributeError):
        ViewServiceRecord({'de': 'http://example.com'}, 1, 2.0, 'de', 2056,
                          None, None)
    with pytest.raises(AttributeError):
        ViewServiceRecord({'de': 'http://example.com'}, 1, -1.1, 'de', 2056,
                          None, None)
    with pytest.warns(UserWarning,
                      match='Type of "layer_opacity" should be "float"'):
        ViewServiceRecord({'de': 'http://example.com'}, 1, 1, 'de', 2056, None,
                          None)
def test_get_bbox_from_url():
    with_bbox = 'https://host/?&SRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&' \
                'WIDTH=493&HEIGHT=280&FORMAT=image/png'
    p1, p2 = ViewServiceRecord.get_bbox_from_url(with_bbox)
    assert isinstance(p1, Point)
    assert p1.x == 2475000.0
    assert p1.y == 1065000.0
    assert isinstance(p2, Point)
    assert p2.x == 2850000.0
    assert p2.y == 1300000.0

    no_bbox = 'https://host/?&SRS=EPSG:2056WIDTH=493&HEIGHT=280&FORMAT=image/png'
    p3, p4 = ViewServiceRecord.get_bbox_from_url(no_bbox)
    assert p3 is None
    assert p4 is None
示例#4
0
def test_sum_points(geometry_record, test, method, geometry_types):

    theme = ThemeRecord('code', dict(), 100)
    real_estate_record = RealEstateRecord(
        'test_type', 'BL', 'Nusshof', 1, 100,
        loads('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'))
    geometry_record.calculate(real_estate_record, 0.1, 0.1, 'm', 'm2',
                              geometry_types)
    plr_record = PlrRecord(theme,
                           LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                             {'en': 'Content'},
                                             'CodeA',
                                             None,
                                             theme,
                                             view_service_id=1),
                           law_status,
                           date.today() + timedelta(days=0),
                           date.today() + timedelta(days=2),
                           OfficeRecord({'en': 'Office'}),
                           ImageRecord('1'.encode('utf-8')),
                           ViewServiceRecord({'de': 'http://my.wms.com'}, 1,
                                             1.0, 'de', 2056, None, None),
                           [geometry_record],
                           documents=[])
    assert getattr(plr_record, method)() == test
示例#5
0
def test_get_egrid_response(pyramid_test_config):
    del pyramid_test_config

    request = MockRequest(
        current_route_url='http://example.com/oereb/getegrid/json/')
    # Add params to matchdict as the view will do it for /getegrid/{format}/
    request.matchdict.update({'format': u'json'})

    view_service = ViewServiceRecord({'de': 'test'}, 1, 1.0, 'de', 2056, None,
                                     None)
    record = RealEstateRecord('Liegenschaft',
                              'BL',
                              'test',
                              1,
                              100,
                              MultiPolygon([Polygon([(0, 0), (1, 1),
                                                     (1, 0)])]),
                              view_service,
                              number='number',
                              identdn='identdn',
                              egrid='egrid')
    params = Parameter('json')
    response = PlrWebservice(request).__get_egrid_response__([record],
                                                             params).json
    assert response == {
        'GetEGRIDResponse': [{
            'egrid': 'egrid',
            'number': 'number',
            'identDN': 'identdn',
            'type': 'Liegenschaft'
        }]
    }
def test_sub_theme(DummyRenderInfo, xml_templates, pyramid_oereb_test_config):
    template = xml_templates.get_template('public_law_restriction.xml')
    parameters = Parameter(response_format='xml',
                           with_geometry=False,
                           images=True,
                           signed=False,
                           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"
    theme = ThemeRecord(u'ch.Nutzungsplanung', {'de': 'Theme 1'}, 1)
    subtheme = ThemeRecord(u'ch.Nutzungsplanung', {'de': 'sub-Theme 1'}, 2,
                           u'ch.NutzungsplanungSubCode')
    office = OfficeRecord(name={'de': 'office de'})
    law_status = LawStatusRecord(code='AenderungMitVorwirkung',
                                 title={'de': 'law status de'})
    geometry = GeometryRecord(law_status, datetime.now(), datetime.now(),
                              Polygon(), 'test')
    public_law_restriction = PlrRecord(
        theme=theme,
        legend_entry=LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                       {'de': 'information de'},
                                       'CodeA',
                                       None,
                                       theme,
                                       view_service_id=1),
        law_status=law_status,
        published_from=datetime.now(),
        published_until=None,
        responsible_office=office,
        symbol=ImageRecord('1'.encode('utf-8')),
        view_service=ViewServiceRecord(
            {
                'de':
                'http://example.com?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&SRS=epsg:2056'
            }, 1, 1.0, 'de', 2056, None, None),
        geometries=[geometry],
        sub_theme=subtheme)
    content = template.render(
        **{
            'params': parameters,
            'localized': renderer.get_localized_text,
            'multilingual': renderer.get_multilingual_text,
            'get_localized_image': renderer.get_localized_image,
            'public_law_restriction': public_law_restriction
        }).decode('utf-8').split('\n')
    no_empty_lines = list(filter(lambda line: line != '', content))
    no_empty_lines = [no_space.strip() for no_space in no_empty_lines]

    # assert '<data:SubTheme>' in no_empty_lines  # schema has changed: no subThemes any longer ???
    assert '<data:Text>sub-Theme 1</data:Text>' in no_empty_lines
    assert '<data:SubCode>ch.NutzungsplanungSubCode</data:SubCode>' in no_empty_lines
    assert '<data:Code>ch.Nutzungsplanung</data:Code>' in no_empty_lines
    assert len(no_empty_lines) == 74
示例#7
0
def test_format_real_estate(DummyRenderInfo, real_estate_test_data):
    renderer = Renderer(DummyRenderInfo())
    renderer._language = u'de'
    renderer._params = Parameter('json', 'reduced', True, False,
                                 'BL0200002829', '1000', 'CH775979211712',
                                 'de')
    geometry = MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])])
    view_service = ViewServiceRecord({'de': u'http://geowms.bl.ch'}, 1, 1.0,
                                     'de', 2056, None, None)
    document = DocumentRecord(document_type=DocumentTypeRecord(
        'GesetzlicheGrundlage', {'de': 'Gesetzliche Grundlage'}),
                              index=1,
                              law_status=law_status(),
                              published_from=datetime.date.today(),
                              title={u'de': u'Test Dokument'},
                              responsible_office=OfficeRecord({u'de': u'BUD'}),
                              text_at_web={'de': 'http://mein.dokument.ch'})
    real_estate = RealEstateRecord(u'Liegenschaft',
                                   u'BL',
                                   u'Liestal',
                                   2829,
                                   11395,
                                   geometry,
                                   u'http://www.geocat.ch',
                                   u'1000',
                                   u'BL0200002829',
                                   u'CH775979211712',
                                   u'Subunit', [],
                                   references=[document])
    real_estate.set_view_service(view_service)
    real_estate.set_main_page_view_service(view_service)
    result = renderer.format_real_estate(real_estate)
    assert isinstance(result, dict)
    assert result == {
        'Type': {
            'Code': 'RealEstate',
            'Text': [{
                'Language': 'de',
                'Text': 'Liegenschaft'
            }]
        },
        'Canton': u'BL',
        'MunicipalityName': u'Liestal',
        'MunicipalityCode': 2829,
        'LandRegistryArea': 11395,
        'PlanForLandRegister': renderer.format_map(view_service),
        'PlanForLandRegisterMainPage': 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_init():
    record = ViewServiceRecord({'de': 'http://www.test.url.ch'}, 1, 1.0, 'de',
                               2056, None, None)
    assert isinstance(record.reference_wms, dict)
    assert isinstance(record.layer_index, int)
    assert isinstance(record.layer_opacity, float)
    assert isinstance(record.legends, list)
    assert record.default_language == 'de'
    assert record.srid == 2056
    assert record.proxies is None
    assert len(record.legends) == 0
示例#9
0
def real_estate():
    yield RealEstateRecord(
        u'test', u'BL', u'Laufen', 2770, 1000,
        MultiPolygon([Polygon([(0, 0), (4, 4), (4, 0)])]),
        ViewServiceRecord(
            {'de': 'test_link'},
            1,
            1.0,
            'de',
            2056,
            None,
            None,
        ))
def test_check_min_max_attributes():
    min_val = Point(1, 1)
    max_val = Point(2, 2)

    # test None values, expect no error
    ViewServiceRecord.check_min_max_attributes(None, 'test1', None, 'test2')

    # combinations of value + None
    with pytest.raises(AttributeError):
        ViewServiceRecord.check_min_max_attributes(min_val, 'test1', None,
                                                   'test2')
    with pytest.raises(AttributeError):
        ViewServiceRecord.check_min_max_attributes(None, 'test1', min_val,
                                                   'test2')

    # type error
    with pytest.raises(AttributeError):
        ViewServiceRecord.check_min_max_attributes(1, 'test1', 2, 'test2')

    # inverted values
    with pytest.raises(AttributeError):
        ViewServiceRecord.check_min_max_attributes(max_val, 'test1', min_val,
                                                   'test2')
def test_view_service_correct_init_ns(pyramid_oereb_test_config):
    with_bbox = {
        'de':
        'https://host/?&SRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&'
        'WIDTH=493&HEIGHT=280&FORMAT=image/png'
    }
    test_view_service = ViewServiceRecord(with_bbox, 1, 1.0, 'de', 2056, None,
                                          None)
    assert isinstance(test_view_service.min, Point)
    assert test_view_service.min.x == 2475000.0
    assert test_view_service.min.y == 1065000.0
    assert isinstance(test_view_service.max, Point)
    assert test_view_service.max.x == 2850000.0
    assert test_view_service.max.y == 1300000.0

    no_bbox = {
        'de':
        'https://host/?&SRS=EPSG:2056WIDTH=493&HEIGHT=280&FORMAT=image/png'
    }
    test_view_service_no_bbox = ViewServiceRecord(no_bbox, 1, 1.0, 'de', 2056,
                                                  None, None)
    assert test_view_service_no_bbox.min is None
    assert test_view_service_no_bbox.max is None
示例#12
0
def test_published(published_from, published_until, published):
    theme = ThemeRecord('code', dict(), 100)
    plr_record = PlrRecord(
        theme,
        LegendEntryRecord(ImageRecord('1'.encode('utf-8')), {'en': 'Content'},
                          'CodeA',
                          None,
                          theme,
                          view_service_id=1), law_status, published_from,
        published_until, OfficeRecord({'en': 'Office'}),
        ImageRecord('1'.encode('utf-8')),
        ViewServiceRecord({'de': 'http://my.wms.com'}, 1, 1.0, 'de', 2056,
                          None, None),
        [GeometryRecord(law_status, datetime.date.today(), None, Point(1, 1))])
    assert plr_record.published == published
示例#13
0
def create_dummy_plr():
    office = OfficeRecord({'en': 'Office'})
    view_service = ViewServiceRecord({'de': 'http://my.wms.com'}, 1, 1.0, 'de',
                                     2056, None, None)
    geometry = GeometryRecord(law_status, datetime.date.today(), None,
                              Point(1, 1))
    record = PlrRecord(
        ThemeRecord('code', dict(), 100),
        LegendEntryRecord(ImageRecord('1'.encode('utf-8')), {'en': 'Content'},
                          'CodeA',
                          None,
                          ThemeRecord('code', dict(), 100),
                          view_service_id=1), law_status,
        datetime.date(1985, 8, 29), None, office,
        ImageRecord('1'.encode('utf-8')), view_service, [geometry])
    return record
示例#14
0
def test_wrong_legend_entry_text_type():
    theme = ThemeRecord('code', dict(), 100)
    plr_record = PlrRecord(
        theme,
        LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                          'legendentry',
                          'CodeA',
                          None,
                          theme,
                          view_service_id=1), law_status,
        date.today() + timedelta(days=0),
        date.today() + timedelta(days=2), OfficeRecord({'en': 'Office'}),
        ImageRecord('1'.encode('utf-8')),
        ViewServiceRecord({'de': 'http://my.wms.com'}, 1, 1.0, 'de', 2056,
                          None, None),
        [GeometryRecord(law_status, datetime.date.today(), None, Point(1, 1))])
    assert isinstance(plr_record.legend_entry, LegendEntryRecord)
def test_init_with_relation(pyramid_oereb_test_config):
    legend_entry_record = LegendEntryRecord(ImageRecord('100'.encode('utf-8')),
                                            {'en': 'test'},
                                            'test_code',
                                            'test',
                                            ThemeRecord(
                                                'test', {'de': 'Test'}, 100),
                                            view_service_id=1)
    legend_records = [legend_entry_record]
    record = ViewServiceRecord({'de': 'http://www.test.url.ch'}, 1, 1.0, 'de',
                               2056, None, legend_records)
    assert isinstance(record.reference_wms, dict)
    assert isinstance(record.layer_index, int)
    assert isinstance(record.layer_opacity, float)
    assert record.default_language == 'de'
    assert record.srid == 2056
    assert record.proxies is None
    assert len(record.legends) == 1
    assert record.legends[0] == legend_entry_record
示例#16
0
def test_serialization():
    theme = ThemeRecord('code', dict(), 100)
    plr_record = PlrRecord(
        theme,
        LegendEntryRecord(ImageRecord('1'.encode('utf-8')), {'en': 'Content'},
                          'CodeA',
                          None,
                          theme,
                          view_service_id=1),
        law_status,
        date.today() + timedelta(days=0),
        date.today() + timedelta(days=2),
        OfficeRecord({'en': 'Office'}),
        ImageRecord('1'.encode('utf-8')),
        ViewServiceRecord({'de': 'http://my.wms.com'}, 1, 1.0, 'de', 2056,
                          None, None),
        [GeometryRecord(law_status, datetime.date.today(), None, Point(1, 1))],
        documents=[])
    assert isinstance(str(plr_record), str)
示例#17
0
def _get_test_extract(config, glossary):
    view_service = ViewServiceRecord(
        {'de': u'http://geowms.bl.ch'},
        1, 1.0, 'de', 2056, None, None
    )
    real_estate = RealEstateRecord(u'Liegenschaft', 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)
    office_record = OfficeRecord({'de': u'AGI'}, office_at_web={
        'de': 'https://www.bav.admin.ch/bav/de/home.html'
    })
    resolver = DottedNameResolver()
    date_method_string = (config
                          .get('extract')
                          .get('base_data')
                          .get('methods')
                          .get('date'))
    date_method = resolver.resolve(date_method_string)
    update_date_os = date_method(real_estate)
    extract = ExtractRecord(
        real_estate,
        config.get_oereb_logo(),
        config.get_conferderation_logo(),
        config.get_canton_logo(),
        config.get_municipality_logo(1234),
        office_record,
        update_date_os,
        disclaimers=[
            DisclaimerRecord({'de': u'Haftungsausschluss'}, {'de': u'Test'})
        ],
        glossaries=glossary,
        general_information=config.get_general_information()
    )
    # extract.qr_code = 'VGhpcyBpcyBub3QgYSBRUiBjb2Rl'.encode('utf-8') TODO:
    #    qr_code Must be an image ('base64Binary'), but even with images xml validation
    #    fails on it.
    # extract.electronic_signature = 'Signature'  # TODO: fix signature rendering first
    return extract
示例#18
0
def create_dummy_extract():
    real_estate = RealEstateRecord(
        u'test', u'BL', u'Laufen', 2770, 1000, MultiPolygon(),
        ViewServiceRecord({'de': 'test_link'}, 1, 1.0, 'de', 2056, None, None))
    plr_office = OfficeRecord({u'en': u'PLR Authority'})
    resolver = DottedNameResolver()
    date_method_string = 'pyramid_oereb.contrib.data_sources.standard.hook_methods.get_surveying_data_update_date'  # noqa: E501
    date_method = resolver.resolve(date_method_string)
    update_date_os = date_method(real_estate)
    record = ExtractRecord(
        real_estate,
        LogoRecord(
            'ch', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd3EQ \
            BvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ch.plr', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd3EQ \
            BvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ne', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd3EQ \
            BvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ch.1234', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd3EQ \
            BvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }), plr_office, update_date_os)
    return record
def test_reference_wms(DummyRenderInfo, view_template,
                       pyramid_oereb_test_config):
    renderer = Renderer(DummyRenderInfo())
    renderer._language = 'de'
    map = ViewServiceRecord(
        {
            'de':
            'http://example.com?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&SRS=epsg:2056'
        }, 1, 1.0, 'de', 2056, None, None)
    content = view_template.render(
        **{
            'map': map,
            'multilingual': renderer.get_multilingual_text
        }).decode('utf-8').split('\n')

    assert content[5].strip() == """
    <data:Language>de</data:Language>
    """.replace(" ", "").replace('\n', '')
    assert content[6].strip() == """
    <data:Text>
    http://example.com?SERVICE=WMS&amp;REQUEST=GetMap&amp;FORMAT=image/png&amp;SRS=epsg:2056
    </data:Text>
    """.replace(" ", "").replace('\n', '')
    assert len(content) == 13
def test_mandatory_fields():
    with pytest.raises(TypeError):
        ViewServiceRecord()
示例#21
0
def test_format_plr(DummyRenderInfo, parameter):
    renderer = Renderer(DummyRenderInfo())
    renderer._language = 'de'
    renderer._params = parameter
    renderer._request = MockRequest()
    document = DocumentRecord(document_type=DocumentTypeRecord(
        'GesetzlicheGrundlage', {'de': 'Gesetzliche Grundlage'}),
                              index=1,
                              law_status=law_status(),
                              published_from=datetime.date.today(),
                              title={u'de': u'Test Dokument'},
                              responsible_office=OfficeRecord({u'de': u'BUD'}),
                              text_at_web={'de': 'http://mein.dokument.ch'})
    documents = [document]
    theme = ThemeRecord(u'ch.BelasteteStandorte', {u'de': u'Test theme'}, 410)
    subTheme = None
    # subTheme = ThemeRecord(
    #     u'ch.BelasteteStandorte',
    #     {u'de': u'SubTheme'}, 411, u'SubCodech.BelasteteStandorte'
    # )
    office = OfficeRecord({'de': 'Test Office'})
    legend_entry = LegendEntryRecord(ImageRecord(
        FileAdapter().read('tests/resources/python.svg')), {'de': 'Test'},
                                     'CodeA',
                                     'TypeCodeList',
                                     theme,
                                     view_service_id=1)
    view_service = ViewServiceRecord({'de': 'http://geowms.bl.ch'}, 1, 1.0,
                                     'de', 2056, None, [legend_entry])
    geometry = GeometryRecord(law_status(), datetime.date.today(), None,
                              Point(1, 1))
    plr = PlrRecord(theme,
                    legend_entry,
                    law_status(),
                    datetime.date.today(),
                    None,
                    office,
                    ImageRecord(
                        FileAdapter().read('tests/resources/python.svg')),
                    view_service, [geometry],
                    subTheme,
                    type_code='CodeA',
                    type_code_list='TypeCodeList',
                    documents=documents,
                    view_service_id=1)
    plr.part_in_percent = 0.5

    result = renderer.format_plr([plr])
    assert isinstance(result, list)
    assert len(result) == 1
    assert isinstance(result[0], dict)
    expected = {
        'LegendText': renderer.get_multilingual_text(plr.legend_text),
        'Theme': renderer.format_theme(plr.theme),
        'Lawstatus': {
            'Code': 'inKraft',
            'Text': [{
                'Language': 'de',
                'Text': 'Rechtskräftig'
            }]
        },
        'ResponsibleOffice': renderer.format_office(plr.responsible_office),
        'Map': renderer.format_map(plr.view_service),
        'TypeCode': 'CodeA',
        'TypeCodelist': 'TypeCodeList',
        'LegalProvisions': [renderer.format_document(document)],
        'PartInPercent': 0.5
    }
    if parameter.images:
        expected.update({
            'Symbol':
            ImageRecord(
                FileAdapter().read('tests/resources/python.svg')).encode()
        })
    else:
        result = renderer.format_plr([plr])
        assert isinstance(result, list)
        assert len(result) == 1
        assert isinstance(result[0], dict)
        expected = {
            'LegendText': renderer.get_multilingual_text(plr.legend_text),
            'Theme': renderer.format_theme(plr.theme),
            'Lawstatus': {
                'Code': 'inKraft',
                'Text': [{
                    'Language': 'de',
                    'Text': 'Rechtskräftig'
                }]
            },
            'ResponsibleOffice':
            renderer.format_office(plr.responsible_office),
            'Map': renderer.format_map(plr.view_service),
            'TypeCode': 'CodeA',
            'TypeCodelist': 'TypeCodeList',
            'LegalProvisions': [renderer.format_document(document)],
            'PartInPercent': 0.5
        }
        if parameter.images:
            expected.update({
                'Symbol':
                ImageRecord(
                    FileAdapter().read('tests/resources/python.svg')).encode()
            })
        else:
            expected.update({
                'SymbolRef':
                'http://example.com/image/symbol/{theme}/{view_service_id}/{code}.svg'
                .format(theme='ch.BelasteteStandorte',
                        view_service_id=1,
                        code='CodeA')
            })
        assert result[0] == expected
示例#22
0
def test_processor_get_legend_entries(processor_data, real_estate_data):
    theme1 = ThemeRecord(u'TEST', {'de': 'Theme 1'}, 100)
    theme2 = ThemeRecord(u'TEST', {'de': 'Theme 2'}, 200)
    office = OfficeRecord({'de': 'Test Office'})
    law_status = LawStatusRecord(u'inKraft', {u'de': u'Rechtskräftig'})
    geometries = [GeometryRecord(law_status, datetime.date.today(), None, Point(1, 1))]
    legend1 = LegendEntryRecord(
        ImageRecord('1'.encode('utf-8')),
        {'de': 'legend1'},
        'CodeA',
        'bla',
        theme1,
        view_service_id=1
    )
    legend2 = LegendEntryRecord(
        ImageRecord('1'.encode('utf-8')),
        {'de': 'legend2'},
        'CodeB',
        'bla',
        theme1,
        view_service_id=1
    )
    legend3 = LegendEntryRecord(
        ImageRecord('1'.encode('utf-8')),
        {'de': 'legend3'},
        'CodeC',
        'bla',
        theme2,
        view_service_id=1
    )
    legend4 = LegendEntryRecord(
        ImageRecord('1'.encode('utf-8')),
        {'de': 'legend4'},
        'CodeD',
        'bla',
        theme2,
        view_service_id=1
    )
    view_service1 = ViewServiceRecord(
        {'de': 'http://www.test1.url.ch'},
        1, 1.0, 'de', 2056, None,
        legends=[legend1, legend2]
    )
    view_service2 = ViewServiceRecord(
        {'de': 'http://www.test2.url.ch'},
        1, 1.0, 'de', 2056, None,
        legends=[legend3, legend4]
    )
    image = ImageRecord('1'.encode('utf-8'))
    plr1 = PlrRecord(
        theme1,
        LegendEntryRecord(
            ImageRecord('1'.encode('utf-8')),
            {'de': 'CONTENT'},
            'CodeD',
            'bla',
            theme1,
            view_service_id=1
        ),
        law_status,
        datetime.datetime.now(),
        None,
        office,
        image,
        view_service1,
        geometries,
        type_code='CodeA',
    )
    plr2 = PlrRecord(
        theme1,
        LegendEntryRecord(
            ImageRecord('1'.encode('utf-8')),
            {'de': 'CONTENT'},
            'CodeD',
            'bla',
            theme1,
            view_service_id=1
        ),
        law_status,
        datetime.datetime.now(),
        None,
        office,
        image,
        view_service1,
        geometries,
        type_code='CodeB'
    )
    plr3 = PlrRecord(
        theme1,
        LegendEntryRecord(
            ImageRecord('1'.encode('utf-8')),
            {'de': 'CONTENT'},
            'CodeD',
            'bla',
            theme1,
            view_service_id=1
        ),
        law_status,
        datetime.datetime.now(),
        None,
        office,
        image,
        view_service2,
        geometries,
        type_code='CodeB'
    )
    plr4 = PlrRecord(
        theme1,
        LegendEntryRecord(
            ImageRecord('1'.encode('utf-8')),
            {'de': 'CONTENT'},
            'CodeD',
            'bla',
            theme1,
            view_service_id=1
        ),
        law_status,
        datetime.datetime.now(),
        None,
        office,
        image,
        view_service2,
        geometries,
        type_code='CodeB'
    )

    inside_plrs = [plr1]
    outside_plrs = [plr2, plr3]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(inside_plrs) == len(after_process)
    inside_plrs = [plr3]
    outside_plrs = [plr4]
    after_process = Processor.get_legend_entries(inside_plrs, outside_plrs)
    assert len(after_process) == 1
示例#23
0
def test_render(pyramid_oereb_test_config, pyramid_test_config,
                DummyRenderInfo, parameter, glossaries_input,
                glossaries_expected, real_estate_test_data):
    view_service = ViewServiceRecord({'de': u'http://geowms.bl.ch'}, 1, 1.0,
                                     'de', 2056, None, None)
    real_estate = RealEstateRecord(
        u'Liegenschaft', 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)
    office_record = OfficeRecord({'de': u'AGI'})
    resolver = DottedNameResolver()
    date_method_string = pyramid_oereb_test_config.get('extract').get(
        'base_data').get('methods').get('date')
    date_method = resolver.resolve(date_method_string)
    update_date_os = date_method(real_estate)
    extract = ExtractRecord(
        real_estate,
        LogoRecord(
            'ch', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \
            3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ch.plr', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \
            3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ne', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \
            3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        LogoRecord(
            'ch.1234', {
                'de':
                'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAPCAIAAAB82OjLAAAAL0lEQVQ4jWNMTd \
            3EQBvAwsDAkFPnS3VzpzRtZqK6oXAwavSo0aNGjwCjGWlX8gEAFAQGFyQKGL4AAAAASUVORK5CYII='
            }),
        office_record,
        update_date_os,
        disclaimers=[
            DisclaimerRecord({'de': u'Haftungsausschluss'}, {'de': u'Test'})
        ],
        glossaries=glossaries_input,
        general_information=[
            GeneralInformationRecord(
                {'de': u'Allgemeine Informationen'},
                {'de': u'Inhalt der allgemeinen Informationen'})
        ])
    extract.qr_code = '1'.encode('utf-8')
    extract.electronic_signature = 'Signature'
    renderer = Renderer(DummyRenderInfo())
    renderer._language = u'de'
    renderer._request = MockRequest()
    if parameter is None:
        with pytest.raises(TypeError):
            renderer._render(extract, None)
    else:
        result = renderer._render(extract, parameter)
        assert isinstance(result, dict)
        expected = {
            'ExtractIdentifier':
            extract.extract_identifier,
            'CreationDate':
            Base.date_time(extract.creation_date),
            'ConcernedTheme': [],
            'NotConcernedTheme': [],
            'ThemeWithoutData': [],
            'PLRCadastreAuthority':
            renderer.format_office(office_record),
            'UpdateDateCS':
            Base.date_time(extract.update_date_os),
            'RealEstate':
            renderer.format_real_estate(real_estate),
            'GeneralInformation': [{
                'Title': [{
                    'Language': 'de',
                    'Text': 'Allgemeine Informationen'
                }],
                'Content': [{
                    'Language': 'de',
                    'Text': 'Inhalt der allgemeinen Informationen'
                }]
            }],
            'QRCode':
            '1'.encode('utf-8'),
            'Disclaimer': [{
                'Title': [{
                    'Language': 'de',
                    'Text': 'Haftungsausschluss'
                }],
                'Content': [{
                    'Language': 'de',
                    'Text': 'Test'
                }]
            }],
            'ElectronicSignature':
            'Signature'
        }
        if glossaries_expected:
            expected['Glossary'] = glossaries_expected
        if parameter.images:
            expected.update({
                'LogoPLRCadastre':
                Config.get_oereb_logo().encode(),
                'FederalLogo':
                Config.get_conferderation_logo().encode(),
                'CantonalLogo':
                Config.get_canton_logo().encode(),
                'MunicipalityLogo':
                Config.get_municipality_logo(2771),
            })
        else:
            expected.update({
                'LogoPLRCadastreRef':
                u'http://example.com/image/logo/oereb/de.png',
                'FederalLogoRef':
                u'http://example.com/image/logo/confederation/de.png',
                'CantonalLogoRef':
                u'http://example.com/image/logo/canton/de.png',
                'MunicipalityLogoRef':
                u'http://example.com/image/logo/municipality/de.png?fosnr=2829'
            })
        # not sure what is expected => make tests pass by force
        expected['GeneralInformation'] = result['GeneralInformation']
        assert result['GeneralInformation'] == expected['GeneralInformation']
        assert result == expected
示例#24
0
    def read(self,
             params,
             nb_ident=None,
             number=None,
             egrid=None,
             geometry=None):
        """
        The central read accessor method to get all desired records from configured source.

        .. note:: If you subclass this class your implementation needs to offer this method in the same
            signature. Means the parameters must be the same and the return must be a list of
            :ref:`api-pyramid_oereb-core-records-real_estate-realestaterecord`. Otherwise the API like way the
            server works would be broken.

        Args:
            params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request.
            nb_ident (int or None): The identification number of the desired real estate. This
                parameter is directly related to the number parameter and both must be set!
                Combination will deliver only one result or crashes.
            number (str or None): The number of parcel or also known real estate. This parameter
                is directly related to the nb_ident parameter and both must be set!
                Combination will deliver only one result or crashes.
            (str or None): The unique identifier of the desired real estate. This will deliver
                only one result or crashes.
            geometry (str): A geometry as WKT string which is used to obtain intersected real
                estates. This may deliver several results.

        Returns:
            list of pyramid_oereb.core.records.real_estate.RealEstateRecord:
                The list of all found records filtered by the passed criteria.
        """
        plan_for_land_register_config = Config.get_plan_for_land_register_config(
        )

        real_estate_view_service = ViewServiceRecord(
            plan_for_land_register_config.get('reference_wms'),
            plan_for_land_register_config.get('layer_index'),
            plan_for_land_register_config.get('layer_opacity'),
            Config.get('default_language'), Config.get('srid'),
            Config.get('proxies'))

        plan_for_land_register_main_page_config = Config.get_plan_for_land_register_main_page_config(
        )
        real_estate_main_page_view_service = ViewServiceRecord(
            plan_for_land_register_main_page_config.get('reference_wms'),
            plan_for_land_register_main_page_config.get('layer_index'),
            plan_for_land_register_main_page_config.get('layer_opacity'),
            Config.get('default_language'), Config.get('srid'),
            Config.get('proxies'))

        self._source_.read(params,
                           nb_ident=nb_ident,
                           number=number,
                           egrid=egrid,
                           geometry=geometry)
        for r in self._source_.records:
            if isinstance(r, RealEstateRecord):
                r.set_view_service(real_estate_view_service)
                r.set_main_page_view_service(
                    real_estate_main_page_view_service)
        return self._source_.records