Exemplo n.º 1
0
def _parse_location(location: str) -> tuple:
    """ validates and returns the provided location (address or coordinate string) as a coordinate tuple """
    if validator.is_address(location):
        return geocoding_service.geocode(location)
    elif validator.is_valid_coordinate(location):
        return literal_eval(location)
    else:
        raise ValidationError(f'invalid coordinate or location {location}')
def test_geocoding():
    result = geocoding_service.geocode('Oberseestrasse 10, Rapperswil-Jona')
    assert (8.816392, 47.2229673) == result
def test_geocoding_breaking_changes(monkeypatch):
    """ uses different service to test breaking changes in the api """
    mock.mock_geocoding_wrong_url(monkeypatch)
    with pytest.raises(ServiceError):
        geocoding_service.geocode('Oberseestrasse 10, Rapperswil-Jona')
def test_geocoding_unavailable_service(monkeypatch):
    mock.mock_geocoding_unavailable_url(monkeypatch)
    with pytest.raises(ServiceError):
        geocoding_service.geocode('Oberseestrasse 10, Rapperswil-Jona')
def test_geocoding_outside_viewbox():
    with pytest.raises(ValidationError):
        geocoding_service.geocode(
            'Sir Matt Busby Way, Stretford, Manchester M16 0RA')
def test_geocoding_no_coordinates_found():
    with pytest.raises(ValidationError):
        geocoding_service.geocode('Hansmusterweg 14, Zürich')