@@ -59,6 +59,7 @@ def test_parse_request_parameters(self, requests_mock):
5959 public ,
6060 strategy ,
6161 use_cache ,
62+ maximum_executions ,
6263 ) = parse_request_parameters (request )
6364 self .assertEqual ("test_stable_id" , stable_id )
6465 self .assertEqual ("test_dataset_id" , dataset_id )
@@ -67,6 +68,8 @@ def test_parse_request_parameters(self, requests_mock):
6768 self .assertEqual (["test_url" ], urls )
6869 self .assertEqual (True , public )
6970 self .assertEqual ("per-point" , strategy )
71+ self .assertEqual (True , use_cache )
72+ self .assertEqual (1 , maximum_executions )
7073
7174 # Exception should be raised
7275 requests_mock .get .return_value .content = None
@@ -106,6 +109,7 @@ def test_parse_request_parameters_gbfs_station_information(self, requests_mock):
106109 public ,
107110 strategy ,
108111 use_cache ,
112+ maximum_executions ,
109113 ) = parse_request_parameters (request )
110114
111115 self .assertEqual ("stable123" , stable_id )
@@ -115,6 +119,9 @@ def test_parse_request_parameters_gbfs_station_information(self, requests_mock):
115119 self .assertEqual ((2 , 2 ), df .shape )
116120 self .assertEqual ("per-polygon" , strategy )
117121 self .assertEqual (True , public )
122+ # Cache is disabled for GBFS data by default
123+ self .assertEqual (False , use_cache )
124+ self .assertEqual (1 , maximum_executions )
118125
119126 @patch ("parse_request.requests" )
120127 def test_parse_request_parameters_gbfs_vehicle_status (self , requests_mock ):
@@ -136,6 +143,7 @@ def test_parse_request_parameters_gbfs_vehicle_status(self, requests_mock):
136143 "vehicle_status_url" : "http://dummy.vehicle" ,
137144 "data_type" : "gbfs" ,
138145 "public" : "False" ,
146+ "maximum_executions" : 10 ,
139147 }
140148
141149 (
@@ -147,6 +155,7 @@ def test_parse_request_parameters_gbfs_vehicle_status(self, requests_mock):
147155 public ,
148156 strategy ,
149157 use_cache ,
158+ maximum_executions ,
150159 ) = parse_request_parameters (request )
151160
152161 self .assertEqual ("stable456" , stable_id )
@@ -156,6 +165,9 @@ def test_parse_request_parameters_gbfs_vehicle_status(self, requests_mock):
156165 self .assertEqual ((2 , 2 ), df .shape )
157166 self .assertEqual ("per-polygon" , strategy )
158167 self .assertEqual (False , public )
168+ # Cache is disabled for GBFS data by default
169+ self .assertEqual (False , use_cache )
170+ self .assertEqual (10 , maximum_executions )
159171
160172 @patch ("parse_request.requests" )
161173 def test_parse_request_parameters_invalid_request (self , requests_mock ):
@@ -406,15 +418,21 @@ def test_update_dataset_bounding_box_exception(self, db_session):
406418 @patch ("reverse_geolocation_processor.update_dataset_bounding_box" )
407419 @patch ("reverse_geolocation_processor.reverse_geolocation" )
408420 @patch ("reverse_geolocation_processor.create_geojson_aggregate" )
421+ @patch ("reverse_geolocation_processor.check_maximum_executions" )
422+ @patch ("reverse_geolocation_processor.get_execution_id" )
409423 def test_valid_request (
410424 self ,
425+ mock_get_execution_id ,
426+ mock_check_maximum_executions ,
411427 mock_create_geojson_aggregate ,
412428 mock_reverse_geolocation ,
413429 mock_update_bounding_box ,
414430 mock_parse_request_parameters ,
415431 ):
416432 from reverse_geolocation_processor import reverse_geolocation_process
417433
434+ mock_get_execution_id .return_value = "test_execution_id"
435+ mock_check_maximum_executions .return_value = None
418436 # Mocking the parsed request parameters
419437 mock_parse_request_parameters .return_value = (
420438 pd .DataFrame ({"stop_lat" : [1.0 ], "stop_lon" : [1.0 ]}),
@@ -425,6 +443,7 @@ def test_valid_request(
425443 True ,
426444 "per-point" ,
427445 False ,
446+ 1 ,
428447 )
429448 mock_update_bounding_box .return_value = MagicMock ()
430449 mock_reverse_geolocation .return_value = {"group_id" : MagicMock ()}
@@ -464,14 +483,21 @@ def test_invalid_request(self, mock_parse_request_parameters):
464483 @patch ("reverse_geolocation_processor.parse_request_parameters" )
465484 @patch ("reverse_geolocation_processor.update_dataset_bounding_box" )
466485 @patch ("reverse_geolocation_processor.reverse_geolocation" )
486+ @patch ("reverse_geolocation_processor.check_maximum_executions" )
487+ @patch ("reverse_geolocation_processor.get_execution_id" )
467488 def test_exception_handling (
468489 self ,
490+ mock_check_get_execution_id ,
491+ mock_check_maximum_executions ,
469492 mock_reverse_geolocation ,
470493 mock_update_bounding_box ,
471494 mock_parse_request_parameters ,
472495 ):
473496 from reverse_geolocation_processor import reverse_geolocation_process
474497
498+ mock_check_get_execution_id .return_value = "test_execution_id"
499+ mock_check_maximum_executions .return_value = None
500+ # mock_dataset_service.get_by_execution_and_stable_ids.return_value = 0
475501 # Mocking the parsed request parameters
476502 mock_parse_request_parameters .return_value = (
477503 pd .DataFrame ({"stop_lat" : [1.0 ], "stop_lon" : [1.0 ]}),
@@ -482,6 +508,7 @@ def test_exception_handling(
482508 True ,
483509 "per-point" ,
484510 False ,
511+ 1 ,
485512 )
486513 mock_update_bounding_box .side_effect = Exception ("Unexpected error" )
487514
@@ -499,12 +526,18 @@ def test_exception_handling(
499526 mock_reverse_geolocation .assert_not_called ()
500527
501528 @patch ("reverse_geolocation_processor.parse_request_parameters" )
529+ @patch ("reverse_geolocation_processor.check_maximum_executions" )
530+ @patch ("reverse_geolocation_processor.get_execution_id" )
502531 def test_valid_request_empty_stops (
503532 self ,
533+ mock_get_execution_id ,
534+ mock_check_maximum_executions ,
504535 mock_parse_request_parameters ,
505536 ):
506537 from reverse_geolocation_processor import reverse_geolocation_process
507538
539+ mock_get_execution_id .return_value = "test_execution_id"
540+ mock_check_maximum_executions .return_value = None
508541 # Mocking the parsed request parameters
509542 mock_parse_request_parameters .return_value = (
510543 pd .DataFrame ({"stop_lat" : [], "stop_lon" : []}),
@@ -515,6 +548,7 @@ def test_valid_request_empty_stops(
515548 True ,
516549 "per-point" ,
517550 False ,
551+ 1 ,
518552 )
519553
520554 # Mocking a Flask request
0 commit comments