def test_getegrid_ident(pyramid_oereb_test_config, schema_json_extract, geometry, real_estate_data): request = MockRequest( current_route_url='http://example.com/oereb/getegrid/json/BLTEST/1000') # Add params to matchdict as the view will do it for /getegrid/{format}/{identdn}/{number} request.matchdict.update({'format': u'json'}) request.params.update({'IDENTDN': u'BLTEST', 'NUMBER': u'1000'}) if geometry: request.params.update({'GEOMETRY': u'true'}) webservice = PlrWebservice(request) response = webservice.get_egrid().json Draft4Validator.check_schema(schema_json_extract) validator = Draft4Validator(schema_json_extract) validator.validate(response) assert isinstance(response, dict) real_estates = response.get('GetEGRIDResponse') assert isinstance(real_estates, list) assert len(real_estates) == 1 assert real_estates[0]['egrid'] == u'TEST' assert real_estates[0]['number'] == u'1000' assert real_estates[0]['identDN'] == u'BLTEST' assert real_estates[0]['type'] == u'Liegenschaft' if geometry: assert 'limit' in real_estates[0] assert 'crs' in real_estates[0]['limit'] assert 'coordinates' in real_estates[0]['limit']
def test_invalid_params(matchdict, params): request = MockRequest() request.matchdict.update(matchdict) request.params.update(params) service = PlrWebservice(request) with pytest.raises(HTTPBadRequest): service.__validate_extract_params__()
def test_return_no_content(): request = MockRequest() request.matchdict.update({'format': 'XML'}) request.params.update({'GEOMETRY': 'true', 'EGRID': 'MISSINGEGRID'}) service = PlrWebservice(request) response = service.get_extract_by_id() assert isinstance(response, HTTPNoContent)
def test_getegrid_address(pyramid_oereb_test_config, schema_json_extract, real_estate_data, address): del pyramid_oereb_test_config request = MockRequest( current_route_url='http://example.com/oereb/getegrid/json/4410/test/10' ) # Add params to matchdict as the view will do it for # /getegrid/{format}/{postalcode}/{localisation}/{number} request.matchdict.update({'format': u'json'}) request.params.update({ 'POSTALCODE': u'4410', 'LOCALISATION': u'test', 'NUMBER': u'10' }) webservice = PlrWebservice(request) response = webservice.get_egrid().json Draft4Validator.check_schema(schema_json_extract) validator = Draft4Validator(schema_json_extract) validator.validate(response) assert isinstance(response, dict) assert response.get('GetEGRIDResponse') is not None assert response.get('GetEGRIDResponse')[0].get('egrid') == u'TEST' assert response.get('GetEGRIDResponse')[0].get('number') == u'1000' assert response.get('GetEGRIDResponse')[0].get('identDN') == u'BLTEST'
def test_matchdict(pyramid_oereb_test_config, matchdict, expected): request = MockRequest() request.matchdict.update(matchdict) request.params.update({'EGRID': 'egrid'}) service = PlrWebservice(request) params = service.__validate_extract_params__() for k, v in expected.items(): assert getattr(params, k) == v
def test_params(params, expected): request = MockRequest() request.matchdict.update({'format': 'XML'}) request.params.update(params) service = PlrWebservice(request) params = service.__validate_extract_params__() for k, v in expected.items(): assert getattr(params, k) == v
def test_format_url(real_estate_data): request = MockRequest() request.matchdict.update({'format': 'URL'}) request.params.update({'EGRID': 'TEST'}) service = PlrWebservice(request) response = service.get_extract_by_id() assert isinstance(response, HTTPFound) assert response.location == 'https://geoview.bl.ch/oereb/?egrid=TEST'
def test_getegrid_coord_missing_parameter(): 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'}) webservice = PlrWebservice(request) response = webservice.get_egrid() assert response.code == 400
def test_get_egrid_coord(pyramid_oereb_test_config, params): 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'}) request.params.update(params) webservice = PlrWebservice(request) webservice.get_egrid()
def test_get_extract_by_id(pyramid_test_config, params): with pyramid_test_config as pyramid_config: pyramid_config.add_renderer( 'pyramid_oereb_extract_json', 'pyramid_oereb.core.renderer.extract.json_.Renderer') request = MockRequest() request.matchdict.update({'format': 'JSON'}) request.params.update(params) service = PlrWebservice(request) service.get_extract_by_id()
def test_process(processor_data, real_estate_data): request = MockRequest() request.matchdict.update(request_matchdict) request.params.update(request_params) processor = create_processor() webservice = PlrWebservice(request) params = webservice.__validate_extract_params__() real_estate = processor.real_estate_reader.read(params, egrid=u'TEST') extract = processor.process(real_estate[0], params, 'http://test.ch') assert isinstance(extract, ExtractRecord)
def test_filter_published_documents(processor_data, real_estate_data, main_schema, land_use_plans): request = MockRequest() request.matchdict.update(request_matchdict) request.params.update(request_params) processor = create_processor() webservice = PlrWebservice(request) params = webservice.__validate_extract_params__() real_estate = processor.real_estate_reader.read(params, egrid=u'TEST') extract = processor.process(real_estate[0], params, 'http://test.ch') plrs = extract.real_estate.public_law_restrictions assert len(plrs) == 1 for plr in plrs: if plr.theme.code == u'ch.Nutzungsplanung': assert len(plr.documents) == 1
def test_process_geometry_testing(processor_data, real_estate_data, land_use_plans): request = MockRequest() request.matchdict.update(request_matchdict) request.params.update(request_params) processor = create_processor() webservice = PlrWebservice(request) params = webservice.__validate_extract_params__() real_estate = processor.real_estate_reader.read(params, egrid=u'TEST') extract = processor.process(real_estate[0], params, 'http://test.ch') plrs = extract.real_estate.public_law_restrictions assert len(plrs) == 1 for plr in plrs: for g in plr.geometries: assert g._test_passed
def test_processor_without_images(processor_data, real_estate_data): request = MockRequest() request.matchdict.update(request_matchdict) request.params.update(request_params) request.params.update({ 'LANG': 'de' }) processor = create_processor() webservice = PlrWebservice(request) params = webservice.__validate_extract_params__() real_estate = processor.real_estate_reader.read(params, egrid=u'TEST') extract = processor.process(real_estate[0], params, 'http://test.ch') assert extract.real_estate.plan_for_land_register.image == {} for plr in extract.real_estate.public_law_restrictions: assert plr.view_service.image == {}
def test_getversions_json(pyramid_oereb_test_config, schema_json_versions): request = MockRequest( current_route_url='http://example.com/oereb/versions/json') # Add params to matchdict as the view will do it for /versions/{format} request.matchdict.update({'format': u'json'}) webservice = PlrWebservice(request) versions = webservice.get_versions().json Draft4Validator.check_schema(schema_json_versions) validator = Draft4Validator(schema_json_versions) validator.validate(versions) assert isinstance(versions, dict) supported_version = versions.get('GetVersionsResponse') assert len(supported_version.get('supportedVersion')) == 1
def test_get_egrid_response(pyramid_test_config): del pyramid_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({'de': 'test'}, 1, 1.0, 'de', 2056, None, None) record = RealEstateRecord('Liegenschaft', 'BL', 'test', 1, 100, MultiPolygon([Polygon([(0, 0), (1, 1), (1, 0)])]), view_service, number='number', identdn='identdn', egrid='egrid') params = Parameter('json') response = PlrWebservice(request).__get_egrid_response__([record], params).json assert response == { 'GetEGRIDResponse': [{ 'egrid': 'egrid', 'number': 'number', 'identDN': 'identdn', 'type': 'Liegenschaft' }] }
def test_processor_sort_by_law_status(processor_data, real_estate_data, main_schema, land_use_plans, contaminated_sites): request = MockRequest() request.matchdict.update(request_matchdict) request.params.update(request_params) processor = create_processor() webservice = PlrWebservice(request) params = webservice.__validate_extract_params__() real_estate = processor.real_estate_reader.read(params, egrid=u'TEST2') extract = processor.process(real_estate[0], params, 'http://test.ch') plrs = extract.real_estate.public_law_restrictions assert len(plrs) == 2 assert plrs[0].theme.code == 'ch.Nutzungsplanung' assert plrs[0].law_status.code == 'inForce' assert plrs[1].theme.code == 'ch.BelasteteStandorte' assert plrs[1].law_status.code == 'inForce'
def test_get_egrid_response_no_content(pyramid_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'}) params = Parameter('json') response = PlrWebservice(request).__get_egrid_response__([], params) assert isinstance(response, HTTPNoContent)
def test_mfp_service(mock_responses, pyramid_test_config, real_estate_data, municipalities, themes, real_estate_types_test_data, logos, general_information ): request = MockRequest() request.matchdict.update({ 'format': 'PDF' }) request.params.update({ # 'GEOMETRY': 'true', 'EGRID': 'TEST', # 'TOPICS': topics }) from pyramid_oereb.core.config import Config pyramid_test_config.add_renderer('pyramid_oereb_extract_print', Config.get('print').get('renderer')) service = PlrWebservice(request) response = service.get_extract_by_id() assert response.status_code == 200
def test_parse_xy(src, dst, buffer_dist): geom = PlrWebservice(MockRequest()).__parse_en__(src, buffer_dist=buffer_dist) if buffer_dist: assert isinstance(geom, Polygon) assert round(geom.area, 2) == round(math.pi, 2) assert round(geom.centroid.x, 3) == round(dst[0], 3) assert round(geom.centroid.y, 3) == round(dst[1], 3) else: assert isinstance(geom, Point) assert round(geom.x, 3) == round(dst[0], 3) assert round(geom.y, 3) == round(dst[1], 3)
def test_getegrid_en(pyramid_oereb_test_config, schema_json_extract, real_estate_data): del pyramid_oereb_test_config url = 'http://example.com/oereb/getegrid/json/?EN=2,0' request = MockRequest(current_route_url=url) # Add params to matchdict as the view will do it for /getegrid/{format}/ request.matchdict.update({'format': u'json'}) request.params.update({'EN': '2,0'}) webservice = PlrWebservice(request) response = webservice.get_egrid().json Draft4Validator.check_schema(schema_json_extract) validator = Draft4Validator(schema_json_extract) validator.validate(response) assert isinstance(response, dict) real_estates = response.get('GetEGRIDResponse') assert isinstance(real_estates, list) assert len(real_estates) == 2 assert real_estates[0]['egrid'] == u'TEST' assert real_estates[0]['number'] == u'1000' assert real_estates[0]['identDN'] == u'BLTEST'
def test_parse_invalid_coordinates(): with pytest.raises(HTTPBadRequest): PlrWebservice(MockRequest()).__parse_gnss__('7.72866') with pytest.raises(HTTPBadRequest): PlrWebservice(MockRequest()).__parse_en__('2621857.856;1259856.578')
def test_parse_gnss(): geom = PlrWebservice(MockRequest()).__parse_gnss__('47.48911,7.72866') assert isinstance(geom, Polygon) assert round(geom.centroid.x, 3) == 2621858.036 assert round(geom.centroid.y, 3) == 1259856.747 assert round(geom.area, 2) == round(math.pi, 2)
def test_return_json(pyramid_oereb_test_config, pyramid_test_config, schema_json_extract, egrid, topics, extract_real_estate_data, main_schema, land_use_plans, contaminated_sites): pyramid_test_config.add_renderer( 'pyramid_oereb_extract_json', 'pyramid_oereb.core.renderer.extract.json_.Renderer') request = MockRequest() request.matchdict.update({'format': 'JSON'}) request.params.update({ 'GEOMETRY': 'true', 'EGRID': egrid, 'TOPICS': topics }) service = PlrWebservice(request) response = service.get_extract_by_id() if topics == 'ALL' and egrid == 'TEST3': assert isinstance(response, HTTPNoContent) return Draft4Validator.check_schema(schema_json_extract) validator = Draft4Validator(schema_json_extract) response = json.loads(response.body.decode('utf-8')) validator.validate(response) assert isinstance(response, dict) extract = response.get('GetExtractByIdResponse').get('extract') real_estate = extract.get('RealEstate') assert isinstance(real_estate, dict) if topics == 'ALL' and egrid == 'TEST': assert len(real_estate.get('RestrictionOnLandownership')) == 2 assert len(extract.get('ConcernedTheme')) == 2 assert len(extract.get('NotConcernedTheme')) == 0 assert len(extract.get('ThemeWithoutData')) == 0 restrictions = real_estate.get('RestrictionOnLandownership') assert restrictions[0]['Theme']['Code'] == 'ch.Nutzungsplanung' assert restrictions[1]['Theme']['Code'] == 'ch.BelasteteStandorte' # simplified dataset, containing only two restrictions insetead of previously 14 if topics == 'ALL_FEDERAL': assert len(real_estate.get('RestrictionOnLandownership')) == 2 assert len(extract.get('ConcernedTheme')) == 2 assert len(extract.get('NotConcernedTheme')) == 0 assert len(extract.get('ThemeWithoutData')) == 0 restrictions = real_estate.get('RestrictionOnLandownership') assert restrictions[0]['Theme']['Code'] == 'ch.Nutzungsplanung' assert restrictions[1]['Theme']['Code'] == 'ch.BelasteteStandorte' if topics == 'ch.BelasteteStandorte,ch.ProjektierungszonenEisenbahnanlagen': assert len(real_estate.get('RestrictionOnLandownership')) == 1 assert len(extract.get('ConcernedTheme')) == 1 assert len(extract.get('NotConcernedTheme')) == 0 assert len(extract.get('ThemeWithoutData')) == 0 restrictions = real_estate.get('RestrictionOnLandownership') assert restrictions[0]['Theme']['Code'] == 'ch.BelasteteStandorte' if topics == 'ALL' and egrid == 'TEST3': assert len(extract.get('ConcernedTheme')) == 3 assert len(extract.get('NotConcernedTheme')) == 14 assert len(extract.get('ThemeWithoutData')) == 0 restrictions = real_estate.get('RestrictionOnLandownership') assert len(restrictions) == 4 assert restrictions[1]['Theme'][ 'Code'] == 'ch.BaulinienNationalstrassen' assert restrictions[1]['Lawstatus']['Code'] == 'changeWithoutPreEffect' assert restrictions[2]['Theme'][ 'Code'] == 'ch.BaulinienNationalstrassen' assert restrictions[2]['Lawstatus']['Code'] == 'inForce'