def test_format_real_estate(config): assert isinstance(config._config, dict) renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = Parameter( 'reduced', 'json', True, False, 'BL0200002829', '1000', 'CH775979211712', 'de') geometry = MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]) view_service = ViewServiceRecord(u'http://geowms.bl.ch', u'http://geowms.bl.ch') document = DocumentRecord(law_status(), datetime.date.today(), {u'de': u'Test Dokument'}, OfficeRecord({u'de': u'BUD'}), {'de': 'http://mein.dokument.ch'}) real_estate = RealEstateRecord(u'RealEstate', u'BL', u'Liestal', 2829, 11395, geometry, u'http://www.geocat.ch', u'1000', u'BL0200002829', u'CH775979211712', u'Subunit', [], references=[document]) real_estate.plan_for_land_register = view_service result = renderer.format_real_estate(real_estate) assert isinstance(result, dict) assert result == { 'Type': u'RealEstate', 'Canton': u'BL', 'Municipality': u'Liestal', 'FosNr': 2829, 'LandRegistryArea': 11395, 'PlanForLandRegister': 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_embeddable(params): renderer = Renderer(DummyRenderInfo()) renderer._language = u'de' renderer._params = params date = datetime.datetime.now() 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.plan_for_land_register = view_service 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) 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', {u'de': u'TEST TEXT'}) datasources = [DatasourceRecord(theme, date, OfficeRecord({u'de': u'Test Office'}))] plr_cadastre_authority = Config.get_plr_cadastre_authority() embeddable = EmbeddableRecord( cadaster_state, plr_cadastre_authority, av_provider_method(real_estate), av_update_date, datasources ) result = renderer.format_embeddable(embeddable) assert result == { 'cadasterOrganisationName': plr_cadastre_authority.name.get('de'), 'datasource': [{ 'topic': { 'Text': {'Text': u'TEST TEXT', 'Language': 'de'}, 'Code': 'TEST' }, 'dataownerName': u'Test Office', 'transferFromSource': date.strftime('%d-%m-%YT%H:%M:%S') }], 'cadasterState': cadaster_state.strftime('%d-%m-%YT%H:%M:%S'), 'dataOwnerNameCadastralSurveying': u'This is only a dummy', 'transferFromSourceCadastralSurveying': av_update_date.strftime('%d-%m-%YT%H:%M:%S') }
def test_get_egrid_response(): with pyramid_oereb_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('test', 1, 1.0, 'test', None) record = RealEstateRecord('test', 'BL', 'test', 1, 100, MultiPolygon( [Polygon([(0, 0), (1, 1), (1, 0)])]), view_service, number='number', identdn='identdn', egrid='egrid') response = PlrWebservice(request).__get_egrid_response__([record]).json assert response == { 'GetEGRIDResponse': [{ 'egrid': 'egrid', 'number': 'number', 'identDN': 'identdn' }] }
def create_dummy_extract(): date = datetime.datetime.now() real_estate = RealEstateRecord( u'test', u'BL', u'Laufen', 2770, 1000, MultiPolygon(), ViewServiceRecord('test_link', 1, 1.0, {'de': 'test_legend'})) plr_office = OfficeRecord({u'en': u'PLR Authority'}) 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', {u'de': u'TEST TEXT'}) datasources = [DatasourceRecord(theme, date, plr_office)] plr_cadastre_authority = Config.get_plr_cadastre_authority() embeddable = EmbeddableRecord(cadaster_state, plr_cadastre_authority, av_provider_method(real_estate), av_update_date, datasources) record = ExtractRecord(real_estate, ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), plr_office, base_data, embeddable) return record
def test_init(): date = datetime.datetime.now() real_estate = RealEstateRecord(u'test', u'BL', u'Laufen', 2770, 1000, MultiPolygon(), ViewServiceRecord( 'test_link', 'test_legend' )) plr_office = OfficeRecord({u'en': u'PLR Authority'}) 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', {u'de': u'TEST TEXT'}) datasources = [DatasourceRecord(theme, date, plr_office)] plr_cadastre_authority = Config.get_plr_cadastre_authority() embeddable = EmbeddableRecord( cadaster_state, plr_cadastre_authority, av_provider_method(real_estate), av_update_date, datasources ) record = ExtractRecord( real_estate, ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), ImageRecord('100'.encode('utf-8')), plr_office, base_data, embeddable ) assert isinstance(record.extract_identifier, str) assert isinstance(record.real_estate, RealEstateRecord) assert isinstance(record.not_concerned_theme, list) assert isinstance(record.concerned_theme, list) assert isinstance(record.theme_without_data, list) assert isinstance(record.creation_date, datetime.date) assert isinstance(record.logo_plr_cadastre, ImageRecord) assert isinstance(record.federal_logo, ImageRecord) assert isinstance(record.cantonal_logo, ImageRecord) assert isinstance(record.municipality_logo, ImageRecord) assert isinstance(record.exclusions_of_liability, list) assert isinstance(record.glossaries, list) assert isinstance(record.plr_cadastre_authority, OfficeRecord) assert isinstance(record.base_data, dict) assert isinstance(record.embeddable, EmbeddableRecord)
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
def test_init(): record = RealEstateRecord('test_type', 'BL', 'Nusshof', 1, 100, loads('POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))')) assert isinstance(record.type, str) assert isinstance(record.canton, str) assert isinstance(record.municipality, str) assert isinstance(record.fosnr, int) assert isinstance(record.land_registry_area, int) assert isinstance(record.limit, Polygon) assert record.metadata_of_geographical_base_data is None assert record.number is None assert record.identdn is None assert record.egrid is None assert record.subunit_of_land_register is None assert record.areas_ratio == 0.01
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
def test_get_egrid_response(): with pyramid_oereb_test_config(): request = MockRequest( current_route_url='http://example.com/oereb/getegrid.json') view_service = ViewServiceRecord('test', 'test') record = RealEstateRecord('test', 'BL', 'test', 1, 100, MultiPolygon( [Polygon([(0, 0), (1, 1), (1, 0)])]), view_service, number='number', identdn='identdn', egrid='egrid') response = PlrWebservice(request).__get_egrid_response__([record]).json assert response == { 'GetEGRIDResponse': [{ 'egrid': 'egrid', 'number': 'number', 'identDN': 'identdn' }] }
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
def test_mandatory_fields(): with pytest.raises(TypeError): RealEstateRecord()