Exemplo n.º 1
0
def bragi_call_test():
    """
    test the whole autocomplete with a geocodejson service
    """
    bragi = GeocodeJson(host='http://bob.com')

    bragi_response = {
        "features": [
            bragi_house_jaures_feature(),
            bragi_house_lefebvre_feature(),
            bragi_street_feature(),
            bragi_admin_feature(),
        ]
    }
    from jormungandr import app

    with app.app_context():
        # we mock the http call to return the hard coded mock_response
        with requests_mock.Mocker() as m:
            m.get(
                'http://bob.com/autocomplete?limit=10&q=rue+bobette&timeout=2000',
                json=bragi_response)
            raw_response = bragi.get({
                'q': 'rue bobette',
                'count': 10
            },
                                     instances=[])
            places = raw_response.get('places')
            assert len(places) == 4
            bragi_house_jaures_response_check(places[0])
            bragi_house_lefebvre_response_check(places[1])
            bragi_street_response_check(places[2])
            bragi_admin_response_check(places[3])
            assert m.called

        with requests_mock.Mocker() as m:
            m.post(
                'http://bob.com/autocomplete?limit=10&q=rue+bobette&timeout=2000',
                json=bragi_response)
            raw_response = bragi.get(
                {
                    'q': 'rue bobette',
                    'count': 10,
                    'shape': geojson()
                },
                instances=[])
            places = raw_response.get('places')
            assert len(places) == 4
            bragi_house_jaures_response_check(places[0])
            bragi_house_lefebvre_response_check(places[1])
            bragi_street_response_check(places[2])
            bragi_admin_response_check(places[3])
            assert m.called
Exemplo n.º 2
0
def test_timestamp_to_datetime():
    # timestamp > MAX_INT
    assert timestamp_to_datetime(18446744071562142720) is None

    with app.app_context():
        g.timezone = pytz.utc
        # test valid date
        assert timestamp_to_datetime(1493296245) == datetime.datetime(2017, 4, 27, 12, 30, 45, tzinfo=pytz.UTC)

        g.timezone = None
        # test valid date but no timezone
        assert timestamp_to_datetime(1493296245) is None
Exemplo n.º 3
0
def bragi_call_test():
    """
    test the whole autocomplete with a geocodejson service
    """
    bragi = GeocodeJson(host='http://bob.com')

    bragi_response = {
        "features": [
            bragi_house_jaures_feature(),
            bragi_house_lefebvre_feature(),
            bragi_street_feature(),
            bragi_admin_feature()
        ]
    }
    mock_requests = MockRequests({
        'http://bob.com/autocomplete?q=rue+bobette&limit=10':
        (bragi_response, 200)
    })
    from jormungandr import app
    with app.app_context():
        # we mock the http call to return the hard coded mock_response
        with mock.patch('requests.get', mock_requests.get):
            raw_response = bragi.get({
                'q': 'rue bobette',
                'count': 10
            },
                                     instances=[])
            places = raw_response.get('places')
            assert len(places) == 4
            bragi_house_jaures_response_check(places[0])
            bragi_house_lefebvre_response_check(places[1])
            bragi_street_response_check(places[2])
            bragi_admin_response_check(places[3])

        with mock.patch('requests.post', mock_requests.get):
            raw_response = bragi.get(
                {
                    'q': 'rue bobette',
                    'count': 10,
                    'shape': geojson()
                },
                instances=[])
            places = raw_response.get('places')
            assert len(places) == 4
            bragi_house_jaures_response_check(places[0])
            bragi_house_lefebvre_response_check(places[1])
            bragi_street_response_check(places[2])
            bragi_admin_response_check(places[3])