Exemple #1
0
def test_tag_image():
    block = ImagesBlock.from_es(
        POI({
            "properties": {
                "name":
                "Musée du Louvre",
                "image":
                "http://upload.wikimedia.org/wikipedia/commons/6/66/Louvre_Museum_Wikimedia_Commons.jpg",
            }
        }),
        lang="en",
    )
    assert block.dict() == {
        "type":
        "images",
        "images": [{
            "url":
            ANY,
            "alt":
            "Musée du Louvre",
            "credits":
            "",
            "source_url":
            "https://commons.wikimedia.org/wiki/File:Louvre_Museum_Wikimedia_Commons.jpg#/media/File:Louvre_Museum_Wikimedia_Commons.jpg",
        }],
    }
Exemple #2
0
def test_phone_block_invalid():
    phone_block = PhoneBlock.from_es(POI(
        {"properties": {
            "contact:phone": "tralala"
        }}),
                                     lang="en")
    assert phone_block is None
Exemple #3
0
def test_phone_block():
    phone_block = PhoneBlock.from_es(POI(
        {"properties": {
            "contact:phone": "tralala"
        }}),
                                     lang='en')
    assert phone_block is None

    phone_block = PhoneBlock.from_es(POI(
        {"properties": {
            "contact:phone": "+33 1 40 20 52 29"
        }}),
                                     lang='en')
    assert phone_block == PhoneBlock(url="tel:+33140205229",
                                     international_format="+33 1 40 20 52 29",
                                     local_format="01 40 20 52 29")
Exemple #4
0
async def _fetch_places_list(params: PlacesQueryParam):
    if params.source == PoiSource.PAGESJAUNES:
        return await run_in_threadpool(
            pj_source.get_places_bbox,
            params.category,
            params.bbox,
            size=params.size,
            query=params.q,
        )
    if params.q:
        # Default source (OSM) with query
        bragi_response = await bragi_client.pois_query_in_bbox(
            query=params.q, bbox=params.bbox, lang=params.lang, limit=params.size
        )
        return [BragiPOI(f) for f in bragi_response.get("features", [])]

    # Default source (OSM) with category or class/subclass filters
    if params.raw_filter:
        filters = [MimirPoiFilter.from_url_raw_filter(f) for f in params.raw_filter]
    else:
        filters = [f for c in params.category for f in c.raw_filters()]

    bbox_places = await run_in_threadpool(
        fetch_es_pois,
        filters=filters,
        bbox=params.bbox,
        max_size=params.size,
    )
    return [POI(p["_source"]) for p in bbox_places]
def test_accessibility_unknown():
    web_block = AccessibilityBlock.from_es(POI(
        {"properties": {
            'wheelchair': 'toto',
        }}),
                                           lang='en')
    assert web_block is None
Exemple #6
0
def test_accessibility_unknown():
    web_block = AccessibilityBlock.from_es(POI(
        {"properties": {
            "wheelchair": "toto",
        }}),
                                           lang="en")
    assert web_block is None
Exemple #7
0
def get_poi(id, es: Elasticsearch, settings: Settings, lang=None) -> POI:
    """Handler that returns points-of-interest"""
    if not lang:
        lang = settings['DEFAULT_LANGUAGE']
    lang = lang.lower()

    es_poi = fetch_es_poi(id, es)
    return POI(es_poi).load_place(lang, verbosity=DEFAULT_VERBOSITY)
Exemple #8
0
def test_website_block():
    web_block = WebSiteBlock.from_es(POI(
        {"properties": {
            "contact:website": "http://www.pershinghall.com"
        }}),
                                     lang="en")

    assert web_block == WebSiteBlock(url="http://www.pershinghall.com")
Exemple #9
0
def test_contact_block():
    web_block = ContactBlock.from_es(POI(
        {"properties": {
            "contact:email": "*****@*****.**"
        }}),
                                     lang="en")

    assert web_block == ContactBlock(url="mailto:[email protected]")
Exemple #10
0
def get_poi(id: str, lang: str = None) -> POI:
    """Handler that returns points-of-interest"""
    es = get_elasticsearch()
    if not lang:
        lang = settings["DEFAULT_LANGUAGE"]
    lang = lang.lower()

    es_poi = fetch_es_poi(id, es)
    return POI(es_poi).load_place(lang, verbosity=DEFAULT_VERBOSITY)
Exemple #11
0
def test_accessibility_block():
    web_block = AccessibilityBlock.from_es(POI(
        {"properties": {
            "wheelchair": "limited",
            "toilets:wheelchair": "no"
        }}),
                                           lang="en")

    assert web_block == AccessibilityBlock(wheelchair="partial",
                                           toilets_wheelchair="no")
def test_accessibility_block():
    web_block = AccessibilityBlock.from_es(POI(
        {"properties": {
            'wheelchair': 'limited',
            'toilets:wheelchair': 'no'
        }}),
                                           lang='en')

    assert web_block == AccessibilityBlock(wheelchair='partial',
                                           toilets_wheelchair='no')
Exemple #13
0
def orsay(lang=None):
    place = {"properties": {}}

    full = read_fixture("fixtures/orsay_museum.json")
    place["administrative_regions"] = full["administrative_regions"]

    key = f"description:{lang}" if lang else "description"
    place["properties"][
        key] = "Le musée d’Orsay est un musée national inauguré en 1986."

    return POI(place)
Exemple #14
0
def test_stars_block_lodging():
    stars_block = StarsBlock.from_es(
        POI({"properties": {"poi_class": "lodging", "stars": "4.5S"}}),
        lang="en",
    )

    assert stars_block == StarsBlock(
        ratings=[
            StarsDetails(has_stars="yes", nb_stars=4.5, kind="lodging"),
        ]
    )
Exemple #15
0
def test_stars_block_restaurant():
    stars_block = StarsBlock.from_es(
        POI({"properties": {"poi_class": "fast_food", "stars": "3"}}),
        lang="en",
    )

    assert stars_block == StarsBlock(
        ratings=[
            StarsDetails(has_stars="yes", nb_stars=3, kind="restaurant"),
        ]
    )
Exemple #16
0
def test_image_tag_wikipedia():
    block = ImagesBlock.from_es(
        POI({
            "properties": {
                "image":
                "https://fr.wikipedia.org/wiki/Fichier:Tour_Eiffel_Wikimedia_Commons.jpg"
            }
        }),
        lang="fr",
    )
    assert block is None
Exemple #17
0
def get_moscow_poi(happy_hours):
    return HappyHourBlock.from_es(POI({
        "coord": {
            "lon": 37.588161523500276,
            "lat": 55.74831406552745
        },
        "properties": {
            "happy_hours": happy_hours
        }
    }),
                                  lang='en')
Exemple #18
0
def get_places_bbox(
    bbox: Any,
    category: Optional[List[str]] = Query(None),
    raw_filter: Optional[List[str]] = Query(None),
    source: Optional[str] = Query(None),
    q: Optional[str] = Query(None),
    size: Optional[int] = Query(None),
    lang: Optional[str] = Query(None),
    verbosity: Optional[str] = Query(None),
):
    es = get_elasticsearch()
    raw_params = get_raw_params(bbox, category, raw_filter, source, q, size, lang, verbosity)
    try:
        params = PlacesQueryParam(**raw_params)
    except ValidationError as e:
        logger.info(f"Validation Error: {e.json()}")
        raise HTTPException(status_code=400, detail=e.errors())

    source = params.source
    if source is None:
        if params.q:
            # PJ is currently the only source that accepts arbitrary queries
            source = SOURCE_PAGESJAUNES
        elif (
            params.category
            and all(c.get("pj_filters") for c in params.category)
            and pj_source.bbox_is_covered(params.bbox)
        ):
            source = SOURCE_PAGESJAUNES
        else:
            source = SOURCE_OSM

    if source == SOURCE_PAGESJAUNES:
        all_categories = [pj_category for c in params.category for pj_category in c["pj_filters"]]
        places_list = pj_source.get_places_bbox(
            all_categories, params.bbox, size=params.size, query=params.q
        )
    else:
        # Default source (OSM)
        if params.raw_filter:
            raw_filters = params.raw_filter
        else:
            raw_filters = [f for c in params.category for f in c["raw_filters"]]

        bbox_places = fetch_bbox_places(
            es, INDICES, raw_filters=raw_filters, bbox=params.bbox, max_size=params.size
        )
        places_list = [POI(p["_source"]) for p in bbox_places]

    return {
        "places": [p.load_place(params.lang, params.verbosity) for p in places_list],
        "source": source,
    }
Exemple #19
0
def test_delivery_block():
    delivery_block = DeliveryBlock.from_es(POI(
        {"properties": {
            "delivery": "yes",
            "takeaway": "yes"
        }}),
                                           lang="en")

    assert delivery_block == DeliveryBlock(
        click_and_collect="unknown",
        delivery="yes",
        takeaway="yes",
    )
Exemple #20
0
def get_oh_block(opening_hours, lat=48.0, lon=2.0, country_code="FR"):
    return OpeningHourBlock.from_es(
        POI({
            "coord": {
                "lon": lon,
                "lat": lat
            },
            "properties": {
                "opening_hours": opening_hours
            },
            "administrative_regions": [{
                "country_codes": [country_code]
            }],
        }),
        lang="en",
    )
def get_moscow_poi(opening_hours):
    """
    returns an OpeningHourBlock from a fake json
    corresponding to a POI located in moscow city
    for different opening_hours formats.
    """
    return OpeningHourBlock.from_es(POI({
        "coord": {
            "lon": 37.588161523500276,
            "lat": 55.74831406552745
        },
        "properties": {
            "opening_hours": opening_hours
        }
    }),
                                    lang='en')
Exemple #22
0
def get_places_bbox(bbox, es: Elasticsearch, indices: IndexNames, settings: Settings, query_params: http.QueryParams):
    raw_params = get_raw_params(query_params)
    try:
        params = PlacesQueryParam(**raw_params)
    except ValidationError as e:
        logger.info(f"Validation Error: {e.json()}")
        raise BadRequest(
            detail={"message": e.errors()}
        )

    source = params.source
    if source is None:
        if params.q:
            # PJ is currently the only source that accepts arbitrary queries
            source = SOURCE_PAGESJAUNES
        elif params.category \
            and all(c.get('pj_filters') for c in params.category) \
            and pj_source.bbox_is_covered(params.bbox):
            source = SOURCE_PAGESJAUNES
        else:
            source = SOURCE_OSM

    if source == SOURCE_PAGESJAUNES:
        all_categories = [pj_category for c in params.category for pj_category in c['pj_filters']]
        places_list = pj_source.get_places_bbox(all_categories, params.bbox, size=params.size, query=params.q)
    else:
        # Default source (OSM)
        if params.raw_filter:
            raw_filters = params.raw_filter
        else:
            raw_filters = [f for c in params.category for f in c['raw_filters']]

        bbox_places = fetch_bbox_places(
            es,
            indices,
            raw_filters=raw_filters,
            bbox=params.bbox,
            max_size=params.size
        )
        places_list = [POI(p['_source']) for p in bbox_places]

    return {
        "places": [p.load_place(params.lang, params.verbosity) for p in places_list],
        "source": source
    }
Exemple #23
0
def test_phone_block_multiple_numbers():
    phone_block = PhoneBlock.from_es(
        POI({
            "properties": {
                "contact:phone": "01 40 20 52 29 ; 01 99 99 99 99"
            },
            "administrative_regions": [{
                "zone_type": "country",
                "country_codes": ["FR"]
            }],
        }),
        lang="en",
    )
    assert phone_block == PhoneBlock(
        url="tel:+33140205229",
        international_format="+33 1 40 20 52 29",
        local_format="01 40 20 52 29",
    )
Exemple #24
0
def test_tag_mapillary():
    block = ImagesBlock.from_es(POI(
        {"properties": {
            "mapillary": "vwf6B4zuu8WPW5K2bqHMVg"
        }}),
                                lang="en")
    assert block.dict() == {
        "type":
        "images",
        "images": [{
            "url":
            ANY,
            "alt":
            "Mapillary",
            "credits":
            "From Mapillary, licensed under CC-BY-SA",
            "source_url":
            "https://www.mapillary.com/app/?focus=photo&pKey=vwf6B4zuu8WPW5K2bqHMVg",
        }],
    }
Exemple #25
0
def get_places_bbox(bbox, es: Elasticsearch, indices: IndexNames,
                    settings: Settings, query_params: http.QueryParams):
    raw_params = dict(query_params)
    if 'raw_filter' in query_params:
        raw_params['raw_filter'] = query_params.get_list('raw_filter')
    try:
        params = PlacesQueryParam(**raw_params)
    except ValidationError as e:
        logger.warning(f"Validation Error: {e.json()}")
        raise BadRequest(detail={"message": e.errors()})

    bbox_places = fetch_bbox_places(es,
                                    indices,
                                    categories=params.raw_filter,
                                    bbox=params.bbox,
                                    max_size=params.size)

    places_list = []
    for p in bbox_places:
        poi = POI.load_place(p['_source'], params.lang, settings,
                             params.verbosity)
        places_list.append(poi)

    return {"places": places_list}
Exemple #26
0
def test_stars_block_invalid():
    stars_block = StarsBlock.from_es(
        POI({"properties": {"stars": "four stars"}}),
        lang="en",
    )
    assert stars_block is None