Ejemplo n.º 1
0
def test_init():
    record = ExclusionOfLiabilityRecord({'en': 'Disclaimer'},
                                        {'en': u'No warranty on nothing.'})
    assert record.title.get('en') == 'Disclaimer'
    assert record.content is not None
    if sys.version_info.major == 2:
        assert isinstance(record.content.get('en'), unicode)  # noqa
    else:
        assert isinstance(record.content.get('en'), str)
Ejemplo n.º 2
0
def get_test_extract():
    date = datetime.datetime.now()
    with pyramid_oereb_test_config():
        view_service = ViewServiceRecord(u'http://geowms.bl.ch',
                                         1,
                                         1.0,
                                         u'http://geowms.bl.ch',
                                         None)
        real_estate = RealEstateRecord(u'RealEstate', 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 = Config.get('extract').get('base_data').get('methods').get('date')
        date_method = resolver.resolve(date_method_string)
        av_update_date = date_method(real_estate)
        base_data = Config.get_base_data(av_update_date)

        av_provider_method_string = Config.get('extract').get('base_data').get('methods').get('provider')
        av_provider_method = resolver.resolve(av_provider_method_string)
        cadaster_state = date
        theme = ThemeRecord(u'TEST', {'de': u'TEST TEXT'})
        datasources = [DatasourceRecord(theme, date, office_record)]
        plr_cadastre_authority = Config.get_plr_cadastre_authority()
        embeddable = EmbeddableRecord(
            cadaster_state,
            plr_cadastre_authority,
            av_provider_method(real_estate),
            av_update_date,
            datasources
        )
        extract = ExtractRecord(
            real_estate,
            ImageRecord('1'.encode('utf-8')),
            ImageRecord('2'.encode('utf-8')),
            ImageRecord('3'.encode('utf-8')),
            ImageRecord('4'.encode('utf-8')),
            office_record,
            base_data,
            embeddable,
            exclusions_of_liability=[
                ExclusionOfLiabilityRecord({'de': u'Haftungsausschluss'}, {'de': u'Test'})
            ],
            glossaries=[GlossaryRecord({'de': u'Glossar'}, {'de': u'Test'})],
            general_information={'de': u'Allgemeine Informationen'},
            certification={'de': u'certification'},
            certification_at_web={'de': u'certification_at_web'},
        )
        # 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
Ejemplo n.º 3
0
def test_render(parameter, glossaries_input, glossaries_expected):
    date = datetime.datetime.now()
    with pyramid_oereb_test_config():
        view_service = ViewServiceRecord(u'http://geowms.bl.ch', 1, 1.0,
                                         {'de': u'http://geowms.bl.ch'}, None)
        real_estate = RealEstateRecord(
            u'RealEstate', 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 = Config.get('extract').get('base_data').get(
            'methods').get('date')
        date_method = resolver.resolve(date_method_string)
        av_update_date = date_method(real_estate)
        base_data = Config.get_base_data(av_update_date)

        av_provider_method_string = Config.get('extract').get('base_data').get(
            'methods').get('provider')
        av_provider_method = resolver.resolve(av_provider_method_string)
        cadaster_state = date
        theme = ThemeRecord(u'TEST', {'de': u'TEST TEXT'})
        datasources = [DatasourceRecord(theme, date, office_record)]
        plr_cadastre_authority = Config.get_plr_cadastre_authority()
        embeddable = EmbeddableRecord(cadaster_state, plr_cadastre_authority,
                                      av_provider_method(real_estate),
                                      av_update_date, datasources)
        extract = ExtractRecord(
            real_estate,
            ImageRecord('1'.encode('utf-8')),
            ImageRecord('2'.encode('utf-8')),
            ImageRecord('3'.encode('utf-8')),
            ImageRecord('4'.encode('utf-8')),
            office_record,
            base_data,
            embeddable,
            exclusions_of_liability=[
                ExclusionOfLiabilityRecord({'de': u'Haftungsausschluss'},
                                           {'de': u'Test'})
            ],
            glossaries=glossaries_input,
            general_information={'de': u'Allgemeine Informationen'},
            certification={'de': u'certification'},
            certification_at_web={'de': u'certification_at_web'},
        )
        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': [],
                'isReduced':
                True,
                'PLRCadastreAuthority':
                renderer.format_office(office_record),
                'BaseData':
                renderer.get_multilingual_text(
                    Config.get_base_data(av_update_date)),
                'RealEstate':
                renderer.format_real_estate(real_estate),
                'Certification': [{
                    'Language': 'de',
                    'Text': 'certification'
                }],
                'CertificationAtWeb': [{
                    'Language': 'de',
                    'Text': 'certification_at_web'
                }],
                'GeneralInformation': [{
                    'Language': 'de',
                    'Text': 'Allgemeine Informationen'
                }],
                'QRCode':
                '1'.encode('utf-8'),
                'ExclusionOfLiability': [{
                    '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':
                    base64.b64encode('1'.encode('utf-8')).decode('ascii'),
                    'FederalLogo':
                    base64.b64encode('2'.encode('utf-8')).decode('ascii'),
                    'CantonalLogo':
                    base64.b64encode('3'.encode('utf-8')).decode('ascii'),
                    'MunicipalityLogo':
                    base64.b64encode('4'.encode('utf-8')).decode('ascii'),
                })
            else:
                expected.update({
                    'LogoPLRCadastreRef':
                    u'http://example.com/image/logo/oereb/de',
                    'FederalLogoRef':
                    u'http://example.com/image/logo/confederation/de',
                    'CantonalLogoRef':
                    u'http://example.com/image/logo/canton/de',
                    'MunicipalityLogoRef':
                    u'http://example.com/image/municipality/2829'
                })
            assert result == expected
Ejemplo n.º 4
0
def test_mandatory_fields():
    with pytest.raises(TypeError):
        ExclusionOfLiabilityRecord()
Ejemplo n.º 5
0
def test_init():
    record = ExclusionOfLiabilityRecord({'en': 'Disclaimer'},
                                        {'en': u'No warranty on nothing.'})
    assert record.title.get('en') == 'Disclaimer'
    assert record.content is not None
    assert isinstance(record.content.get('en'), str)