@@ -172,7 +172,6 @@ def test_get_external_telemetry_config_no_file(
172172    "hostname" , 
173173    "telemetry_service_name" , 
174174    "telemetry_token" , 
175-     "telemetry_proxy_url"  
176175]) 
177176def  test_get_external_telemetry_config_missing_fields (
178177            tmp_path , setup_env , config_path , missing_field 
@@ -196,6 +195,26 @@ def test_get_external_telemetry_config_missing_fields(
196195    check_invalid_get_external_config (tmp_path , expected_error )
197196
198197
198+ def  test_get_external_telemetry_config_missing_proxy_url (
199+             tmp_path , setup_env , config_path 
200+         ):
201+     config_data  =  {
202+         "telemetry_url" : "some/server/url" ,
203+         "hostname" : "gadi" ,
204+         "telemetry_service_name" : "payu" ,
205+         "telemetry_token" : "some_token" ,
206+     }
207+     with  open (config_path , 'w' ) as  f :
208+         json .dump (config_data , f )
209+ 
210+     # Assert no error is raised when proxy URL is missing 
211+     result  =  get_external_telemetry_config (
212+         archive_path = tmp_path  /  "archive" ,
213+         job_file_path = tmp_path  /  "job_file.json" 
214+     )
215+     assert  result  ==  config_data 
216+ 
217+ 
199218def  test_get_external_telemetry_config_invalid_json (
200219            tmp_path , setup_env , config_path 
201220        ):
@@ -536,3 +555,46 @@ def start_side_effect():
536555    with  open (TELEMETRY_1_0_0_SCHEMA_PATH , "r" ) as  f :
537556        schema  =  json .load (f )
538557    jsonschema .validate (sent_data , schema )
558+ 
559+ 
560+ @pytest .mark .parametrize ("proxy_url,expected_proxies" , [ 
561+     (None , None ), 
562+     ("http://proxy.example.com:8080" , { 
563+         "http" : "http://proxy.example.com:8080" , 
564+         "https" : "http://proxy.example.com:8080"  
565+     }) 
566+ ]) 
567+ def  test_post_telemetry_data (tmp_path , proxy_url , expected_proxies ):
568+     """Test the post_telemetry_data function with and without proxy URL""" 
569+ 
570+     with  patch ('requests.post' ) as  mock_post :
571+         mock_response  =  Mock ()
572+         mock_response .status_code  =  200 
573+         mock_response .json .return_value  =  {"status" : "success" }
574+         mock_post .return_value  =  mock_response 
575+ 
576+         post_telemetry_data (
577+             url = "http://example.com/telemetry" ,
578+             token = "test-token" ,
579+             data = {"key" : "value" },
580+             service_name = "test-service" ,
581+             proxy_url = proxy_url ,
582+             archive_path = tmp_path  /  "archive" ,
583+             job_file_path = tmp_path  /  "job_file.json" 
584+         )
585+         assert  mock_post .called 
586+         args , kwargs  =  mock_post .call_args 
587+         assert  args  ==  ("http://example.com/telemetry" ,)
588+         assert  kwargs .get ('headers' ) ==  {
589+             'Content-type' : 'application/json' ,
590+             'Authorization' : 'Token test-token' ,
591+         }
592+         assert  kwargs .get ('timeout' ) ==  10 
593+         assert  kwargs .get ('proxies' ) ==  expected_proxies 
594+         assert  kwargs .get ('data' ) ==  json .dumps (
595+             {
596+                 "service" : "test-service" ,
597+                 "version" : "1.0.0" ,
598+                 "telemetry" : {"key" : "value" }
599+             }
600+         )
0 commit comments