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(), ] } with app.test_request_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&request_id=123', json=bragi_response, ) raw_response = bragi.get( { 'q': 'rue bobette', 'count': 10, 'request_id': '123' }, instances=[]) places = raw_response.get('places') assert len(places) == 4 context_response_check(raw_response) 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&request_id=123', json=bragi_response, ) raw_response = bragi.get( { 'q': 'rue bobette', 'count': 10, "request_id": "123", 'shape': geojson() }, instances=[]) context_response_check(raw_response) 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
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&timeout=2000': (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])