Beispiel #1
0
def test_exception_requests_inalid():
    """Raise exception via requests as response for invalid api_key."""
    ls = LS(api_key="dummy")
    with pytest.raises(ApiError) as execinfo:
        resp = ls.geocode(query="abc")
        raise ApiError(resp)
    resp = execinfo.value.args[0]
    assert resp.status_code == 401
    assert resp.reason == "Unauthorized"
    assert str(execinfo.value).startswith(
        '401, Unauthorized, {"error":"Unauthorized"')
def test_ls_geocoding():
    """Test geocoding api. """
    address = "200 S Mathilda Sunnyvale CA"
    ls = LS(api_key=LS_API_KEY)
    resp = ls.geocode(query=address, limit=2)
    assert isinstance(resp, GeocoderResponse)
    assert resp.__str__()
    assert resp.as_json_string()
    geo_json = resp.to_geojson()
    assert geo_json.type == "FeatureCollection"
    assert geo_json.features
    pos = resp.items[0]["position"]
    assert len(resp.items) == 2
    assert pos == {"lat": 37.37634, "lng": -122.03405}
def test_ls_geocoding_exception():
    """Test geocoding api exception."""
    address = "Goregaon West, Mumbai 400062, India"

    ls = LS(api_key="dummy")
    with pytest.raises(ApiError):
        ls.geocode(query=address)
    with pytest.raises(ValueError):
        ls.geocode(query="")
        ls.geocode(query="   ")