def read(self, real_estate, municipality, params): """ This method finally creates the extract. .. 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 :ref:`api-pyramid_oereb-lib-records-extract-extractrecord`. Otherwise the API like way the server works would be broken. Args: real_estate (pyramid_oereb.lib.records.real_estate.RealEstateRecord): The real estate for which the report should be generated municipality (pyramid_oereb.lib.records.municipiality.MunicipalityRecord): The municipality record. params (pyramid_oereb.views.webservice.Parameter): The parameters of the extract request. Returns: pyramid_oereb.lib.records.extract.ExtractRecord: The extract record containing all gathered data. """ log.debug("read() start") assert isinstance(municipality.logo, ImageRecord) bbox = ViewServiceRecord.get_bbox(real_estate.limit) bbox = box(bbox[0], bbox[1], bbox[2], bbox[3]) datasource = list() concerned_themes = list() not_concerned_themes = list() themes_without_data = list() if municipality.published: for plr_source in self._plr_sources_: if not params.skip_topic(plr_source.info.get('code')): log.debug("read() going to read from plr_source {}".format( plr_source)) plr_source.read(real_estate, bbox) log.debug("read() done reading from plr_source {}".format( plr_source)) for ds in plr_source.datasource: if not params.skip_topic(ds.theme.code): datasource.append(ds) real_estate.public_law_restrictions.extend( plr_source.records) for plr in real_estate.public_law_restrictions: # Filter topics due to topics parameter if not params.skip_topic(plr.theme.code): if isinstance(plr, PlrRecord): contained = False for theme in concerned_themes: if theme.code == plr.theme.code: contained = True if not contained: concerned_themes.append(plr.theme) elif isinstance(plr, EmptyPlrRecord): if plr.has_data: not_concerned_themes.append(plr.theme) else: themes_without_data.append(plr.theme) else: for plr_source in self._plr_sources_: themes_without_data.append( Config.get_theme(plr_source.info.get('code'))) # Load base data form configuration 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) general_information = Config.get('extract').get('general_information') 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 = datetime.datetime.now() embeddable = EmbeddableRecord(cadaster_state, self.plr_cadastre_authority, av_provider_method(real_estate), av_update_date, datasource) self.extract = ExtractRecord(real_estate, self.logo_plr_cadastre, self.federal_logo, self.cantonal_logo, municipality.logo, self.plr_cadastre_authority, base_data, embeddable, self.certification, self.certification_at_web, concerned_theme=concerned_themes, not_concerned_theme=not_concerned_themes, theme_without_data=themes_without_data, general_information=general_information) log.debug("read() done") return self.extract
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', 'FederalLogoRef': u'http://example.com/image/logo/confederation', 'CantonalLogoRef': u'http://example.com/image/logo/canton', 'MunicipalityLogoRef': u'http://example.com/image/municipality/2829' }) assert result == expected