Exemple #1
0
    def test_find_places_by_geojson(self):
        ctx = new_test_service_context()

        geojson_obj = {
            'type':
            'Polygon',
            'coordinates': (((2.0, 49.0), (2.0, 55.0), (-1.0, 55.0),
                             (-1.0, 49.0), (2.0, 49.0)), )
        }
        places = find_places(ctx, "all", geojson_obj=geojson_obj)
        self._assertPlaceGroup(places, 2, {'0', '3'})

        geojson_obj = {
            'type': 'Feature',
            'properties': {},
            'geometry': geojson_obj
        }
        places = find_places(ctx, "all", geojson_obj=geojson_obj)
        self._assertPlaceGroup(places, 2, {'0', '3'})

        geojson_obj = {'type': 'FeatureCollection', 'places': [geojson_obj]}
        places = find_places(ctx, "all", geojson_obj=geojson_obj)
        self._assertPlaceGroup(places, 2, {'0', '3'})

        with self.assertRaises(ServiceBadRequestError) as cm:
            geojson_obj = {'type': 'FeatureCollection', 'places': []}
            find_places(ctx, "all", geojson_obj=geojson_obj)
        self.assertEqual("HTTP 400: Received invalid GeoJSON object",
                         f"{cm.exception}")
Exemple #2
0
    def test_find_places_by_wkt(self):
        ctx = new_test_service_context()
        places = find_places(ctx, "all", geom_wkt="POLYGON ((2 49, 2 55, -1 55, -1 49, 2 49))")
        self._assertPlaceGroup(places, 2, {'0', '3'})

        with self.assertRaises(ServiceBadRequestError) as cm:
            find_places(ctx, "all", geom_wkt="POLYGLON ((2 49, 2 55, -1 55, -1 49, 2 49))")
        self.assertEqual("HTTP 400: Received invalid geometry WKT", f"{cm.exception}")
Exemple #3
0
    def test_find_places_by_box(self):
        ctx = new_test_service_context()
        places = find_places(ctx, "all", box_coords="-1,49,2,55")
        self._assertPlaceGroup(places, 2, {'0', '3'})

        with self.assertRaises(ServiceBadRequestError) as cm:
            find_places(ctx, "all", box_coords="-1,49,55")
        self.assertEqual("HTTP 400: Received invalid bounding box geometry", f"{cm.exception}")

        with self.assertRaises(ServiceBadRequestError) as cm:
            find_places(ctx, "all", box_coords="-1,49,x,55")
        self.assertEqual("HTTP 400: Received invalid bounding box geometry", f"{cm.exception}")
Exemple #4
0
 def post(self, place_group_id: str):
     query_expr = self.params.get_query_argument("query", None)
     comb_op = self.params.get_query_argument("comb", "and")
     geojson_obj = self.get_body_as_json_object()
     response = find_places(self.service_context,
                            place_group_id,
                            self.base_url,
                            geojson_obj=geojson_obj,
                            query_expr=query_expr, comb_op=comb_op)
     self.set_header('Content-Type', "application/json")
     self.write(json.dumps(response, indent=2))
Exemple #5
0
 def get(self, place_group_id: str):
     query_expr = self.params.get_query_argument("query", None)
     geom_wkt = self.params.get_query_argument("geom", None)
     box_coords = self.params.get_query_argument("bbox", None)
     comb_op = self.params.get_query_argument("comb", "and")
     if geom_wkt and box_coords:
         raise ServiceBadRequestError('Only one of "geom" and "bbox" may be given')
     response = find_places(self.service_context,
                            place_group_id,
                            self.base_url,
                            geom_wkt=geom_wkt, box_coords=box_coords,
                            query_expr=query_expr, comb_op=comb_op)
     self.set_header('Content-Type', "application/json")
     self.write(json.dumps(response, indent=2))
Exemple #6
0
 def test_find_places_all(self):
     ctx = new_test_service_context()
     places = find_places(ctx, "all", "http://localhost:9090")
     self._assertPlaceGroup(places, 6, {'0', '1', '2', '3', '4', '5'})