50
50
}
51
51
52
52
53
- def direct_path_response_valid ():
53
+ def direct_path_response_valid (ebike ):
54
54
"""
55
55
A mock of a valid response from geovelo.
56
56
Reply to POST of {"starts":[[48.803064,2.443385, "refStart1"]],
57
57
"ends":[[48.802049,2.426482, "refEnd1"]]}
58
58
Modify with caution as it will affect every tests using these start and end uris.
59
59
"""
60
+ duration = 2822 if ebike else 3155
60
61
return [
61
62
{
62
63
"distances" : {
@@ -65,7 +66,7 @@ def direct_path_response_valid():
65
66
"recommendedRoads" : 7759.0 ,
66
67
"total" : 11393.0 ,
67
68
},
68
- "duration" : 3155 ,
69
+ "duration" : duration ,
69
70
"estimatedDatetimeOfArrival" : "2017-02-24T16:52:08.711" ,
70
71
"estimatedDatetimeOfDeparture" : "2017-02-24T15:59:33.711" ,
71
72
"id" : "bG9jPTQ4Ljg4Nzk0LDIuMzE0MzM4JmxvYz00OC44Mjk5MjcsMi4zNzY3NDcjQkVHSU5ORVIjRmFsc2UjQkVHSU5ORVIjMTMjRmFsc2UjRmFsc2UjMjAxNy0wMi0yNCAxNTo1OTozMy43MTEwNjgjVFJBRElUSU9OQUwjMCMwI1JFQ09NTUVOREVEI0ZhbHNl" ,
@@ -116,7 +117,7 @@ def direct_path_response_valid():
116
117
"profile" : "BEGINNER" ,
117
118
"verticalGain" : 51 ,
118
119
},
119
- "duration" : 3155 ,
120
+ "duration" : duration ,
120
121
"estimatedDatetimeOfArrival" : "2017-02-24T16:52:08.711" ,
121
122
"estimatedDatetimeOfDeparture" : "2017-02-24T15:59:33.711" ,
122
123
"geometry" : "_yzf|AszglClL`ShClEzCrHj@nNnBfD~AoHfDeD`nBmeC|AqBvAuAhWyWjVqUbJsJdd@uf@uPwh@sBgG{JoYmEkMeEwLxv@iu@}Hwj@k@}DcCqQ{Ims@m@yEbBcDbCyEhEiIhSm`@rPy\\ bI}OfBwD|H}CaNehA}MwiAzA_LiBsPa@sDoBaSeAoKiCcHqBQmG{Rqk@meAa@oHRwSDuDv^yfChAmAnAk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ZoXjE{Dt^e\\ |AnDzAhDzJwK]eAg@CTpBrGeBzBkBk@eBHa@J_AeAY}@}ClCiCw@wJ[cAeB?gScp@YtCxBjH~DvM" ,
@@ -238,7 +239,15 @@ def make_data_test():
238
239
'''{
239
240
"starts": [[48.2, 2.0, null]], "ends": [[48.3, 3.0, null], [48.4, 4.0, null]],
240
241
"transportMode": "BIKE",
241
- "bikeDetails": {"profile": "MEDIAN", "averageSpeed": 12, "bikeType": "TRADITIONAL"}}'''
242
+ "bikeDetails": {"profile": "MEDIAN", "averageSpeed": 12, "bikeType": "TRADITIONAL", "eBike": false}}'''
243
+ )
244
+
245
+ data = Geovelo ._make_request_arguments_isochrone (origins , destinations , use_ebike = True )
246
+ assert ujson .loads (ujson .dumps (data )) == ujson .loads (
247
+ '''{
248
+ "starts": [[48.2, 2.0, null]], "ends": [[48.3, 3.0, null], [48.4, 4.0, null]],
249
+ "transportMode": "BIKE",
250
+ "bikeDetails": {"profile": "MEDIAN", "averageSpeed": 12, "bikeType": "TRADITIONAL", "eBike": true}}'''
242
251
)
243
252
244
253
@@ -272,54 +281,76 @@ def get_matrix_test():
272
281
def direct_path_geovelo_test ():
273
282
instance = MagicMock ()
274
283
geovelo = Geovelo (instance = instance , service_url = MOCKED_SERVICE_URL )
275
- resp_json = direct_path_response_valid ()
276
284
277
285
origin = make_pt_object (type_pb2 .ADDRESS , lon = 2 , lat = 48.2 , uri = 'refStart1' )
278
286
destination = make_pt_object (type_pb2 .ADDRESS , lon = 3 , lat = 48.3 , uri = 'refEnd1' )
279
287
fallback_extremity = PeriodExtremity (str_to_time_stamp ('20161010T152000' ), False )
280
288
with requests_mock .Mocker () as req :
289
+
290
+ def json_matcher (request , _ ):
291
+ req_data = request .json ()
292
+ return direct_path_response_valid (req_data .get ("bikeDetails" , {}).get ("eBike" ))
293
+
281
294
req .post (
282
295
'{}/api/v2/computedroutes?instructions=true&elevations=true&geometry=true'
283
296
'&single_result=true&bike_stations=false&objects_as_ids=true&' .format (MOCKED_SERVICE_URL ),
284
- json = resp_json ,
285
- )
286
- geovelo_resp = geovelo .direct_path_with_fp (
287
- instance , 'bike' , origin , destination , fallback_extremity , MOCKED_REQUEST , None , None
297
+ json = json_matcher ,
288
298
)
289
- assert geovelo_resp .status_code == 200
290
- assert geovelo_resp .response_type == response_pb2 .ITINERARY_FOUND
291
- assert len (geovelo_resp .journeys ) == 1
292
- assert geovelo_resp .journeys [0 ].duration == 3155 # 52min35s
293
- assert geovelo_resp .journeys [0 ].requested_date_time == 0 # parameter datetime absent in MOCKED_REQUEST
294
- assert len (geovelo_resp .journeys [0 ].sections ) == 1
295
- assert geovelo_resp .journeys [0 ].arrival_date_time == str_to_time_stamp ('20161010T152000' )
296
- assert geovelo_resp .journeys [0 ].departure_date_time == str_to_time_stamp ('20161010T142725' )
297
- assert geovelo_resp .journeys [0 ].sections [0 ].type == response_pb2 .STREET_NETWORK
298
- assert geovelo_resp .journeys [0 ].sections [0 ].type == response_pb2 .STREET_NETWORK
299
- assert geovelo_resp .journeys [0 ].sections [0 ].duration == 3155
300
- assert geovelo_resp .journeys [0 ].sections [0 ].length == 11393
301
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .coordinates [2 ].lon == 2.314258
302
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .coordinates [2 ].lat == 48.887428
303
- assert geovelo_resp .journeys [0 ].sections [0 ].origin == origin
304
- assert geovelo_resp .journeys [0 ].sections [0 ].destination == destination
305
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].name == "Rue Jouffroy d'Abbans"
306
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].direction == 0
307
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].length == 40
308
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].duration == 11
309
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [0 ].distance_from_start == 0
310
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [0 ].elevation == 45.5
311
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [1 ].distance_from_start == 128
312
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [1 ].elevation == 44
313
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [2 ].distance_from_start == 274
314
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [2 ].elevation == 50
315
- assert geovelo_resp .journeys [0 ].sections [0 ].cycle_lane_length == 98
316
- assert len (geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information ) == 3
317
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [0 ].cycle_path_type == 2
318
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [0 ].length == 58.0
319
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [1 ].cycle_path_type == 2
320
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [1 ].length == 40.0
321
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [2 ].cycle_path_type == 2
322
- assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [2 ].length == 0.0
299
+
300
+ def _test (request ):
301
+
302
+ use_ebike = Geovelo .use_ebike (request )
303
+
304
+ geovelo_resp = geovelo .direct_path_with_fp (
305
+ instance , 'bike' , origin , destination , fallback_extremity , request , None , None
306
+ )
307
+ assert geovelo_resp .status_code == 200
308
+ assert geovelo_resp .response_type == response_pb2 .ITINERARY_FOUND
309
+ assert len (geovelo_resp .journeys ) == 1
310
+ assert geovelo_resp .journeys [0 ].duration == 2822 if use_ebike else 3155
311
+ assert geovelo_resp .journeys [0 ].arrival_date_time == str_to_time_stamp ('20161010T152000' )
312
+ assert geovelo_resp .journeys [0 ].departure_date_time == str_to_time_stamp (
313
+ '20161010T143258' if use_ebike else '20161010T142725'
314
+ )
315
+ assert (
316
+ geovelo_resp .journeys [0 ].requested_date_time == 0
317
+ ) # parameter datetime absent in MOCKED_REQUEST
318
+ assert len (geovelo_resp .journeys [0 ].sections ) == 1
319
+ assert geovelo_resp .journeys [0 ].sections [0 ].type == response_pb2 .STREET_NETWORK
320
+ assert geovelo_resp .journeys [0 ].sections [0 ].type == response_pb2 .STREET_NETWORK
321
+ assert geovelo_resp .journeys [0 ].sections [0 ].duration == 2822 if use_ebike else 3155
322
+ assert geovelo_resp .journeys [0 ].sections [0 ].length == 11393
323
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .coordinates [2 ].lon == 2.314258
324
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .coordinates [2 ].lat == 48.887428
325
+ assert geovelo_resp .journeys [0 ].sections [0 ].origin == origin
326
+ assert geovelo_resp .journeys [0 ].sections [0 ].destination == destination
327
+ assert (
328
+ geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].name == "Rue Jouffroy d'Abbans"
329
+ )
330
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].direction == 0
331
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].length == 40
332
+ assert (
333
+ geovelo_resp .journeys [0 ].sections [0 ].street_network .path_items [1 ].duration == 10
334
+ if use_ebike
335
+ else 11
336
+ )
337
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [0 ].distance_from_start == 0
338
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [0 ].elevation == 45.5
339
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [1 ].distance_from_start == 128
340
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [1 ].elevation == 44
341
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [2 ].distance_from_start == 274
342
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .elevations [2 ].elevation == 50
343
+ assert geovelo_resp .journeys [0 ].sections [0 ].cycle_lane_length == 98
344
+ assert len (geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information ) == 3
345
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [0 ].cycle_path_type == 2
346
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [0 ].length == 58.0
347
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [1 ].cycle_path_type == 2
348
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [1 ].length == 40.0
349
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [2 ].cycle_path_type == 2
350
+ assert geovelo_resp .journeys [0 ].sections [0 ].street_network .street_information [2 ].length == 0.0
351
+
352
+ _test (MOCKED_REQUEST )
353
+ _test (dict ({"bike_type" : "ebike" }, ** MOCKED_REQUEST ))
323
354
324
355
325
356
def direct_path_geovelo_zero_test ():
@@ -392,7 +423,7 @@ def distances_durations_test():
392
423
"""
393
424
instance = MagicMock ()
394
425
geovelo = Geovelo (instance = instance , service_url = MOCKED_SERVICE_URL )
395
- resp_json = direct_path_response_valid ()
426
+ resp_json = direct_path_response_valid (False )
396
427
397
428
origin = make_pt_object (type_pb2 .ADDRESS , lon = 2 , lat = 48.2 , uri = 'refStart1' )
398
429
destination = make_pt_object (type_pb2 .ADDRESS , lon = 3 , lat = 48.3 , uri = 'refEnd1' )
@@ -417,16 +448,22 @@ def make_request_arguments_bike_details_test():
417
448
"""
418
449
instance = MagicMock ()
419
450
geovelo = Geovelo (instance = instance , service_url = MOCKED_SERVICE_URL )
420
- data = geovelo ._make_request_arguments_bike_details (bike_speed_mps = 3.33 )
451
+ data = geovelo ._make_request_arguments_bike_details (bike_speed_mps = 3.33 , use_ebike = False )
421
452
assert ujson .loads (ujson .dumps (data )) == ujson .loads (
422
453
'''{"profile": "MEDIAN", "averageSpeed": 12,
423
- "bikeType": "TRADITIONAL"}'''
454
+ "bikeType": "TRADITIONAL","eBike": false}'''
455
+ )
456
+
457
+ data = geovelo ._make_request_arguments_bike_details (bike_speed_mps = 4.1 , use_ebike = False )
458
+ assert ujson .loads (ujson .dumps (data )) == ujson .loads (
459
+ '''{"profile": "MEDIAN", "averageSpeed": 15,
460
+ "bikeType": "TRADITIONAL","eBike": false}'''
424
461
)
425
462
426
- data = geovelo ._make_request_arguments_bike_details (bike_speed_mps = 4.1 )
463
+ data = geovelo ._make_request_arguments_bike_details (bike_speed_mps = 4.1 , use_ebike = True )
427
464
assert ujson .loads (ujson .dumps (data )) == ujson .loads (
428
465
'''{"profile": "MEDIAN", "averageSpeed": 15,
429
- "bikeType": "TRADITIONAL"}'''
466
+ "bikeType": "TRADITIONAL","eBike": true }'''
430
467
)
431
468
432
469
0 commit comments