def test_matrix(valid_here_matrix): instance = MagicMock() instance.walking_speed = 1.12 here = Here(instance=instance, service_base_url='bob.com', app_id='toto', app_code='tata') origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) with requests_mock.Mocker() as req: req.get(requests_mock.ANY, json=valid_here_matrix, status_code=200) response = here.get_street_network_routing_matrix( [origin], [destination, destination, destination], mode='walking', max_duration=42, request={'datetime': str_to_time_stamp('20170621T174600')}, ) assert response.rows[0].routing_response[0].duration == 440 assert response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert response.rows[0].routing_response[1].duration == -1 assert response.rows[0].routing_response[ 1].routing_status == response_pb2.unreached assert response.rows[0].routing_response[2].duration == 701 assert response.rows[0].routing_response[ 2].routing_status == response_pb2.reached
def test_post_matrix(valid_matrix_post_resp): instance = MagicMock() instance.walking_speed = 1.12 here = Here(instance=instance, service_base_url='bob.com', apiKey='toto') origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) with requests_mock.Mocker() as req: req.post(requests_mock.ANY, json=valid_matrix_post_resp, status_code=202) post_resp = here.post_matrix_request( [origin], [destination, destination, destination], request={'datetime': str_to_time_stamp('20170621T174600')}, ) assert post_resp['status'] == 'accepted' assert post_resp['matrixId'] == 'ca6631e0-6e2a-48cd-a359-f3a4f21d0e54'
def test_matrix_timeout(): instance = MagicMock() instance.walking_speed = 1.12 here = Here(instance=instance, service_base_url='bob.com', app_id='toto', app_code='tata') origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) with requests_mock.Mocker() as req: # a HERE timeout should raise a TechnicalError req.get(requests_mock.ANY, exc=requests.exceptions.Timeout) with pytest.raises(TechnicalError): here.get_street_network_routing_matrix( [origin], [destination, destination, destination], mode='walking', max_duration=42, request={'datetime': str_to_time_stamp('20170621T174600')})
def status_test(): here = Here( instance=None, service_base_url='http://bob.com', id=u"tata-é$~#@\"*!'`§èû", modes=["walking", "bike", "car"], timeout=89, ) status = here.status() assert len(status) == 6 assert status['id'] == u'tata-é$~#@"*!\'`§èû' assert status['class'] == "Here" assert status['modes'] == ["walking", "bike", "car"] assert status['timeout'] == 89 assert status['max_points'] == 100 assert len(status['circuit_breaker']) == 3 assert status['circuit_breaker']['current_state'] == 'closed' assert status['circuit_breaker']['fail_counter'] == 0 assert status['circuit_breaker']['reset_timeout'] == 60
def test_feed_publisher(): walking_service = Kraken(instance=None, service_url='https://bob.com', id=u"walking_service_id", modes=["walking"]) car_service = Here(instance=None, service_base_url='https://bobobo.com', id=u"car_service_id", modes=["car"], timeout=1) car_with_park = CarWithPark(instance=None, walking_service=walking_service, car_service=car_service) fp_car_service = car_service.feed_publisher() fp_car_with_park = car_with_park.feed_publisher() assert fp_car_service == fp_car_with_park assert fp_car_with_park.id == "here" assert fp_car_with_park.license == "Private" assert fp_car_with_park.name == "here" assert fp_car_with_park.url == "https://developer.here.com/terms-and-conditions"
def test_get_matrix(valid_matrix_get_resp, valid_matrix_post_resp): instance = MagicMock() instance.walking_speed = 1.12 here = Here(instance=instance, service_base_url='bob.com', apiKey='toto') origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841) destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307) with requests_mock.Mocker() as req: req.get(requests_mock.ANY, json=valid_matrix_get_resp, status_code=200) response = here.get_matrix_response( [origin], [destination, destination, destination, destination], post_resp=valid_matrix_post_resp) assert response.rows[0].routing_response[0].duration == 7146 assert response.rows[0].routing_response[ 0].routing_status == response_pb2.reached assert response.rows[0].routing_response[1].duration == 7434 assert response.rows[0].routing_response[ 1].routing_status == response_pb2.reached assert response.rows[0].routing_response[2].duration == 12927 assert response.rows[0].routing_response[ 2].routing_status == response_pb2.reached assert response.rows[0].routing_response[3].duration == 14838 assert response.rows[0].routing_response[ 3].routing_status == response_pb2.reached
def status_test(): here = Here( instance=None, service_base_url='http://bob.com', id=u"tata-é$~#@\"*!'`§èû", modes=["walking", "bike", "car"], timeout=89, ) status = here.status() assert len(status) == 11 assert status['id'] == u'tata-é$~#@"*!\'`§èû' assert status['class'] == "Here" assert status['modes'] == ["walking", "bike", "car"] assert status['timeout'] == 89 assert status['matrix_type'] == "simple_matrix" assert status['max_matrix_points'] == 100 assert status['realtime_traffic'] == "enabled" assert status['language'] == "en-gb" assert status['engine_type'] == "diesel" assert status['engine_average_consumption'] == 7 assert len(status['circuit_breaker']) == 3 assert status['circuit_breaker']['current_state'] == 'closed' assert status['circuit_breaker']['fail_counter'] == 0 assert status['circuit_breaker']['reset_timeout'] == 60