コード例 #1
0
def test_request_fails(requests_mocker):
    requests_mocker.get(
        'https://geocode-maps.yandex.ru/1.x/?geocode=b&format=json',
        status_code=400)

    with pytest.raises(YandexGeocoderHttpException,
                       message='Non-200 response from yandex geocoder'):
        Client.request('b')
コード例 #2
0
def get_text_by_coordinates(coordinates):
    try:
        result = Client.request(f'{coordinates[1]}, {coordinates[0]}')
        return result['GeoObjectCollection']['featureMember'][0]['GeoObject'][
            'name']
    except Exception as e:
        print(e)
        return None
コード例 #3
0
def test_request_ok(requests_mocker):
    requests_mocker.get(
        'https://geocode-maps.yandex.ru/1.x/?geocode=b&format=json',
        json={'response': {
            'ok': True
        }})

    assert Client.request('b') == {'ok': True}