Exemplo n.º 1
0
def test_extract_collection(input_geom, result, extracted):
    law_status_record = LawStatusRecord("runningModifications",
                                        {u'de': u'BlaBla'})
    geometry_record = GeometryRecord(law_status_record,
                                     datetime.date(1985, 8, 29), input_geom,
                                     'test')
    assert geometry_record._extract_collection(result) == extracted
Exemplo n.º 2
0
def test_calculate(geometry, real_estate_geometry, length_limit, area_limit,
                   length_share, area_share, nr_of_points, test):
    law_status_record = LawStatusRecord("runningModifications",
                                        {u'de': u'BlaBla'})
    geometry_record = GeometryRecord(law_status_record,
                                     datetime.date(1985, 8, 29), geometry,
                                     'test')
    real_estate = RealEstateRecord('Liegenschaft', 'BL', 'Aesch BL', 2761, 1,
                                   real_estate_geometry)
    geometry_record.calculate(real_estate, length_limit, area_limit, 'm', 'm2')
    assert geometry_record._test_passed == test
    assert geometry_record._length_share == length_share
    assert geometry_record._area_share == area_share
    assert geometry_record._nr_of_points == nr_of_points
Exemplo n.º 3
0
def test_init():
    record = GeometryRecord("runningModifications", datetime.date(1985, 8, 29),
                            Polygon(), 'test')
    assert isinstance(record.law_status, str)
    assert isinstance(record.published_from, datetime.date)
    assert isinstance(record.geo_metadata, str)
    assert isinstance(record.geom, Polygon)
    assert record.public_law_restriction is None
    assert record.office is None
Exemplo n.º 4
0
def create_dummy_plr():
    office = OfficeRecord({'en': 'Office'})
    view_service = ViewServiceRecord('http://my.wms.com', 1, 1.0)
    law_status = LawStatusRecord.from_config(u'inForce')
    geometry = GeometryRecord(law_status, datetime.date.today(), Point(1, 1))
    record = PlrRecord(ThemeRecord('code',
                                   dict()), {'en': 'Content'}, law_status,
                       datetime.date(1985, 8, 29), office,
                       ImageRecord('1'.encode('utf-8')), view_service,
                       [geometry])
    return record
Exemplo n.º 5
0
def test_init(law_status):
    office = OfficeRecord({'en': 'Office'})
    view_service = ViewServiceRecord('http://my.wms.com')
    geometry = GeometryRecord(law_status, datetime.date.today(), Point(1, 1))
    record = PlrRecord(
        ThemeRecord('code', dict()), {'en': 'Content'}, law_status, datetime.date(1985, 8, 29), office,
        ImageRecord('1'.encode('utf-8')), view_service, [geometry])
    assert record.information == {'en': 'Content'}
    assert record.sub_theme is None
    assert isinstance(record.geometries, list)
    assert isinstance(record.responsible_office, OfficeRecord)
    assert isinstance(record.theme, ThemeRecord)
    assert isinstance(record.symbol, ImageRecord)
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
Exemplo n.º 7
0
def test_processor_get_legend_entries():
    theme1 = ThemeRecord(u'TEST', {'de': 'Theme 1'})
    theme2 = ThemeRecord(u'TEST', {'de': 'Theme 2'})
    office = OfficeRecord({'de': 'Test Office'})
    law_status = LawStatusRecord.from_config(u'inForce')
    geometries = [
        GeometryRecord(law_status, datetime.date.today(), 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(
        'http://www.test1.url.ch',
        1,
        1.0,
        legend_at_web={'de': 'http://www.test1.url.ch'},
        legends=[legend1, legend2])
    view_service2 = ViewServiceRecord(
        'http://www.test2.url.ch',
        1,
        1.0,
        legend_at_web={'de': 'http://www.test2.url.ch'},
        legends=[legend3, legend4])
    image = ImageRecord('1'.encode('utf-8'))
    plr1 = PlrRecord(
        theme1,
        {'de': 'CONTENT'},
        law_status,
        datetime.datetime.now(),
        office,
        image,
        view_service1,
        geometries,
        type_code='CodeA',
    )
    plr2 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service1,
                     geometries,
                     type_code='CodeB')
    plr3 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code='CodeB')
    plr4 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     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
Exemplo n.º 8
0
def test_format_plr(parameter):
    with pyramid_oereb_test_config():
        renderer = Renderer(DummyRenderInfo())
        renderer._language = 'de'
        renderer._params = parameter
        renderer._request = MockRequest()
        document = DocumentRecord('Law', law_status(), datetime.date.today(),
                                  {u'de': u'Test Dokument'},
                                  OfficeRecord({u'de': u'BUD'}),
                                  {'de': 'http://mein.dokument.ch'})
        if parameter.flavour == 'reduced':
            documents = [document]
        else:
            documents = None
        theme = ThemeRecord(u'ContaminatedSites', {u'de': u'Test theme'})
        office = OfficeRecord({'de': 'Test Office'})
        legend_entry = LegendEntryRecord(ImageRecord(
            base64.b64encode('1'.encode('utf-8'))), {'de': 'Test'},
                                         'CodeA',
                                         'TypeCodeList',
                                         theme,
                                         view_service_id=1)
        view_service = ViewServiceRecord('http://geowms.bl.ch', 1, 1.0,
                                         {'de': u'http://geowms.bl.ch'},
                                         [legend_entry])
        geometry = GeometryRecord(law_status(), datetime.date.today(),
                                  Point(1, 1))
        plr = PlrRecord(theme, {'de': 'Test'},
                        law_status(),
                        datetime.date.today(),
                        office,
                        ImageRecord('1'.encode('utf-8')),
                        view_service, [geometry],
                        sub_theme={'de': 'Subtopic'},
                        other_theme='Additional topic',
                        type_code='CodeA',
                        type_code_list='TypeCodeList',
                        documents=documents,
                        view_service_id=1)
        plr.part_in_percent = 0.5
        if parameter.flavour == 'full':
            with pytest.raises(ValueError):
                renderer.format_plr([plr])
        else:
            result = renderer.format_plr([plr])
            assert isinstance(result, list)
            assert len(result) == 1
            assert isinstance(result[0], dict)
            expected = {
                'Information': renderer.get_multilingual_text(plr.information),
                'Theme': renderer.format_theme(plr.theme),
                'Lawstatus': {
                    'Code': 'inForce',
                    'Text': {
                        'Language': 'de',
                        'Text': 'In Kraft'
                    }
                },
                'ResponsibleOffice':
                renderer.format_office(plr.responsible_office),
                'Map': renderer.format_map(plr.view_service),
                'SubTheme': 'Subtopic',
                'OtherTheme': 'Additional topic',
                'TypeCode': 'CodeA',
                'TypeCodelist': 'TypeCodeList',
                'LegalProvisions': [renderer.format_document(document)],
                'PartInPercent': 0.5
            }
            if parameter.images:
                expected.update({
                    'Symbol':
                    base64.b64encode('1'.encode('utf-8')).decode('ascii')
                })
            else:
                expected.update({
                    'SymbolRef':
                    'http://example.com/image/symbol/{theme}/{view_service_id}/{code}'
                    .format(theme='ContaminatedSites',
                            view_service_id=1,
                            code='CodeA')
                })
            assert result[0] == expected
Exemplo n.º 9
0
                   })
])
def test_format_document(params, document, result_dict):
    renderer = Renderer(DummyRenderInfo())
    renderer._language = u'de'
    renderer._params = params
    result = renderer.format_document(document)
    assert isinstance(result, dict)
    assert result == result_dict


@pytest.mark.parametrize(
    'geometry,result_dict',
    [(GeometryRecord(law_status(),
                     datetime.date.today(),
                     Point(0, 0),
                     geo_metadata='http://www.geocat.ch',
                     office=OfficeRecord({u'de': u'AGI'})), {
                         'Lawstatus': {
                             'Code': 'inForce',
                             'Text': {
                                 'Language': 'de',
                                 'Text': 'In Kraft'
                             }
                         },
                         'ResponsibleOffice': {
                             'Name': [{
                                 'Language': 'de',
                                 'Text': 'AGI'
                             }]
                         },
Exemplo n.º 10
0
def test_geom_dim(geom, dim):
    assert GeometryRecord.geom_dim(geom) == dim
Exemplo n.º 11
0
def test_mandatory_fields():
    with pytest.raises(TypeError):
        GeometryRecord()
Exemplo n.º 12
0
def test_processor_get_legend_entries(law_status):
    theme1 = ThemeRecord(u'TEST', {'de': 'Theme 1'})
    theme2 = ThemeRecord(u'TEST', {'de': 'Theme 2'})
    office = OfficeRecord({'de': 'Test Office'})
    geometries = [
        GeometryRecord(law_status, datetime.date.today(), Point(1, 1))
    ]
    legend1 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend1'}, u'type1', u'bla', theme1)
    legend2 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend2'}, u'type2', u'bla', theme1)
    legend3 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend3'}, u'type3', u'bla', theme2)
    legend4 = LegendEntryRecord(ImageRecord('1'.encode('utf-8')),
                                {'de': 'legend4'}, u'type4', u'bla', theme2)
    view_service1 = ViewServiceRecord('http://www.test1.url.ch',
                                      'http://www.test1.url.ch',
                                      legends=[legend1, legend2])
    view_service2 = ViewServiceRecord('http://www.test2.url.ch',
                                      'http://www.test2.url.ch',
                                      legends=[legend3, legend4])
    image = ImageRecord('1'.encode('utf-8'))
    plr1 = PlrRecord(
        theme1,
        {'de': 'CONTENT'},
        law_status,
        datetime.datetime.now(),
        office,
        image,
        view_service1,
        geometries,
        type_code=u'type1',
    )
    plr2 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service1,
                     geometries,
                     type_code=u'type2')
    plr3 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code=u'type2')
    plr4 = PlrRecord(theme1, {'de': 'CONTENT'},
                     law_status,
                     datetime.datetime.now(),
                     office,
                     image,
                     view_service2,
                     geometries,
                     type_code=u'type2')

    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