def test_parse():
    element = XML("""
    <OeREBKRMtrsfr_V1_1.Transferstruktur.DarstellungsDienst TID="ch.admin.bazl.sizo.wms">
        <Legende>
            <OeREBKRMtrsfr_V1_1.Transferstruktur.LegendeEintrag>
                <Symbol>
                    <BINBLBOX>test</BINBLBOX>
                </Symbol>
                <LegendeText>
                    <LocalisationCH_V1.MultilingualText>
                        <LocalisedText>
                            <LocalisationCH_V1.LocalisedText>
                                <Language>de</Language>
                                <Text>Sicherheitszonenperimeter</Text>
                            </LocalisationCH_V1.LocalisedText>
                            <LocalisationCH_V1.LocalisedText>
                                <Language>fr</Language>
                                <Text>Périmètre de la zone de sécurité</Text>
                            </LocalisationCH_V1.LocalisedText>
                            <LocalisationCH_V1.LocalisedText>
                                <Language>it</Language>
                                <Text>Perimetro della zona di sicurezza</Text>
                            </LocalisationCH_V1.LocalisedText>
                        </LocalisedText>
                    </LocalisationCH_V1.MultilingualText>
                </LegendeText>
                <ArtCode>108-T-01</ArtCode>
                <ArtCodeliste>https://models.geo.admin.ch/BAZL/SafetyZonePlan_Catalogues_V1_2_20181102.xml</ArtCodeliste>
                <Thema>SicherheitszonenplanFlughafen</Thema>
                <SubThema>A SubTheme</SubThema>
            </OeREBKRMtrsfr_V1_1.Transferstruktur.LegendeEintrag>
        </Legende>
    </OeREBKRMtrsfr_V1_1.Transferstruktur.DarstellungsDienst>
    """)
    session = MockSession()
    legend_entry = LegendEntry(
        session,
        LegendEntryModel,
        'AirportsSecurityZonePlans'
    )
    legend_entry.parse(element)
    parsed = session.getData()
    assert len(parsed) == 1
    assert parsed[0].id == 'ch.admin.bazl.sizo.wms.legende.1'
    assert parsed[0].symbol == 'test'
    assert parsed[0].legend_text['de'] == 'Sicherheitszonenperimeter'
    assert parsed[0].type_code == '108-T-01'
    assert parsed[0].type_code_list == 'https://models.geo.admin.ch/BAZL/' \
                                       'SafetyZonePlan_Catalogues_V1_2_20181102.xml'
    assert parsed[0].topic == 'AirportsSecurityZonePlans'
    assert parsed[0].sub_theme == {
        'de': 'A SubTheme'
    }
    assert parsed[0].other_theme is None
    assert parsed[0].view_service_id == 'ch.admin.bazl.sizo.wms'
def test_parse_symbol():
    element = XML("""
    <LegendeEintrag>
        <Symbol>
            <BINBLBOX>test</BINBLBOX>
        </Symbol>
    </LegendeEintrag>
    """)
    legend_entry = LegendEntry('foo', 'bar', 'baz')
    assert legend_entry._parse_symbol(element, 'foo') is None
    assert legend_entry._parse_symbol(element, 'Symbol') == 'test'
def test_parse():
    element = XML("""
    <OeREBKRMtrsfr_V1_1.Transferstruktur.DarstellungsDienst TID="ch.admin.bazl.sizo.wms">
        <VerweisWMS>https://wms.geo.admin.ch/?SERVICE=WMS&amp;REQUEST=GetMap&amp;VERSION=1.1.1&amp;LAYERS=ch.bazl.sicherheitszonenplan.oereb&amp;STYLES=default&amp;SRS=EPSG:21781&amp;BBOX=475000,60000,845000,310000&amp;WIDTH=740&amp;HEIGHT=500&amp;FORMAT=image/png</VerweisWMS>
        <LegendeImWeb>http://example.com</LegendeImWeb>
    </OeREBKRMtrsfr_V1_1.Transferstruktur.DarstellungsDienst>
    """)
    legend_entry_session = MockSession()
    legend_entry = LegendEntry(legend_entry_session, LegendEntryModel, 'AirportsSecurityZonePlans')
    view_service_session = MockSession()
    view_service = ViewService(view_service_session, ViewServiceModel, legend_entry)
    view_service.parse(element)
    parsed = view_service_session.getData()
    assert len(parsed) == 1
    assert parsed[0].reference_wms == 'https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.1.1' \
                                      '&LAYERS=ch.bazl.sicherheitszonenplan.oereb&STYLES=default' \
                                      '&SRS=EPSG:21781&BBOX=475000,60000,845000,310000&WIDTH=740' \
                                      '&HEIGHT=500&FORMAT=image/png'
    assert parsed[0].legend_at_web == {'de': 'http://example.com'}
Exemplo n.º 4
0
    def _parse_transfer_structure(self,
                                  session,
                                  transfer_structure,
                                  laws=False):
        """
        Parses the transfer structure content.

        Args:
            session (sqlalchemy.orm.session.Session): The SQLAlchemy session for database interaction.
            transfer_structure (lxml.etree.Element): The transfer structure element.
            laws (bool): True if the parsed file is the XML containing the federal laws.
        """

        office = Office(session, self._models.Office)
        document = Document(session, self._models.Document)
        article = Article(session, self._models.Article)
        legend_entry = LegendEntry(session, self._models.LegendEntry,
                                   self._topic_settings.get('code'))
        view_service = ViewService(session, self._models.ViewService,
                                   legend_entry)
        public_law_restriction = PublicLawRestriction(
            session, self._models.PublicLawRestriction,
            self._topic_settings.get('code'))
        geometry = Geometry(session,
                            self._models.Geometry,
                            self._topic_settings.get('geometry_type'),
                            self._srid,
                            arc_max_diff=self._arc_max_diff,
                            arc_precision=self._arc_precision)
        document_reference = DocumentReference(session,
                                               self._models.DocumentReference)
        public_law_restriction_document = PublicLawRestrictionDocument(
            session, self._models.PublicLawRestrictionDocument)
        reference_definition = ReferenceDefinition(
            session, self._models.ReferenceDefinition,
            self._topic_settings.get('code'))
        document_reference_definition = DocumentReferenceDefinition(
            session, self._models.DocumentReferenceDefinition)
        base_refinement = BaseRefinement(
            session, self._models.PublicLawRestrictionBase,
            self._models.PublicLawRestrictionRefinement)

        for element in transfer_structure:
            tag = get_tag(element)
            if tag == self.TAG_OFFICE:
                # Use the last office ID for data integration
                self._data_integration_office_id = element.attrib['TID']
                office.parse(element)
            elif tag == self.TAG_DOCUMENT:
                document.parse(element, 'Law' if laws else 'Hint')
            elif tag == self.TAG_LEGAL_PROVISION:
                document.parse(element, 'LegalProvision')
            elif tag == self.TAG_ARTICLE:
                article.parse(element)
            elif tag == self.TAG_VIEW_SERVICE:
                view_service.parse(element)
            elif tag == self.TAG_PLR:
                public_law_restriction.parse(element)
            elif tag == self.TAG_GEOMETRY:
                geometry.parse(element)
            elif tag == self.TAG_DOCUMENT_REFERENCE:
                document_reference.parse(element)
            elif tag == self.TAG_PUBLIC_LAW_RESTRICTION_DOCUMENT:
                public_law_restriction_document.parse(element)
            elif tag == self.TAG_REFERENCE_DEFINITION:
                reference_definition.parse(element)
            elif tag == self.TAG_DOCUMENT_REFERENCE_DEFINITION:
                document_reference_definition.parse(element)
            elif tag == self.TAG_BASE_REFINEMENT:
                base_refinement.parse(element)
            else:
                self._log.error('NOT IMPLEMENTED: {0}'.format(
                    get_tag(element)))
def test_init():
    legend_entry = LegendEntry('foo', 'bar', 'baz')
    assert legend_entry._session == 'foo'
    assert legend_entry._model == 'bar'
    assert legend_entry._topic_code == 'baz'