@@ -289,14 +289,14 @@ def test_client_with_patterns(self):
289289 assert handler .index_patterns == patterns
290290
291291 @pytest .mark .parametrize (
292- ("username" , "password" ),
292+ ("username" , "password" , "expect_http_auth" ),
293293 [
294- ("admin" , "secret" ),
295- ("admin" , "" ),
296- ("" , "secret" ),
294+ ("admin" , "secret" , True ),
295+ ("admin" , "" , True ),
296+ ("" , "secret" , True ),
297297 ],
298298 )
299- def test_client_with_auth (self , username , password ):
299+ def test_client_with_auth (self , username , password , expect_http_auth ):
300300 """If either username or password are provided, the handler should pass http_auth to the client."""
301301 handler = OpensearchTaskHandler (
302302 base_log_folder = self .local_log_location ,
@@ -313,26 +313,11 @@ def test_client_with_auth(self, username, password):
313313 )
314314
315315 transport_args = handler .client .transport .kwargs
316- assert "http_auth" in transport_args
317- assert transport_args ["http_auth" ] == (username , password )
318-
319- def test_client_no_auth (self ):
320- """If both username and password are empty, the handler should _not_ pass http_auth to the client."""
321- handler = OpensearchTaskHandler (
322- base_log_folder = self .local_log_location ,
323- end_of_log_mark = self .end_of_log_mark ,
324- write_stdout = self .write_stdout ,
325- host = "localhost" ,
326- port = 9200 ,
327- username = "" ,
328- password = "" ,
329- json_format = self .json_format ,
330- json_fields = self .json_fields ,
331- host_field = self .host_field ,
332- offset_field = self .offset_field ,
333- )
334-
335- assert "http_auth" not in handler .client .transport .kwargs
316+ if expect_http_auth :
317+ assert "http_auth" in transport_args
318+ assert transport_args ["http_auth" ] == (username , password )
319+ else :
320+ assert "http_auth" not in handler .client .transport .kwargs
336321
337322 @pytest .mark .db_test
338323 @pytest .mark .parametrize ("metadata_mode" , ["provided" , "none" , "empty" ])
@@ -833,14 +818,14 @@ def test_upload_returns_early_when_ti_is_none(self, tmp_path):
833818 self .opensearch_io .upload (log_file , ti = None )
834819
835820 @pytest .mark .parametrize (
836- ("username" , "password" ),
821+ ("username" , "password" , "expect_http_auth" ),
837822 [
838- ("admin" , "secret" ),
839- ("admin" , "" ),
840- ("" , "secret" ),
823+ ("admin" , "secret" , True ),
824+ ("admin" , "" , True ),
825+ ("" , "secret" , True ),
841826 ],
842827 )
843- def test_client_with_auth (self , username , password ):
828+ def test_client_with_auth (self , username , password , expect_http_auth ):
844829 """If either username or password are provided, the IO should pass http_auth to the client."""
845830 opensearch_io = OpensearchRemoteLogIO (
846831 write_to_opensearch = True ,
@@ -854,25 +839,12 @@ def test_client_with_auth(self, username, password):
854839 log_id_template = "{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}" ,
855840 )
856841
857- transport_args = opensearch_io .client .transport .kwargs
858- assert "http_auth" in transport_args
859- assert transport_args ["http_auth" ] == (username , password )
860-
861- def test_client_no_auth (self ):
862- """If both username and password are empty, the IO should _not_ pass http_auth to the client."""
863- opensearch_io = OpensearchRemoteLogIO (
864- write_to_opensearch = True ,
865- write_stdout = True ,
866- delete_local_copy = True ,
867- host = "localhost" ,
868- port = 9200 ,
869- username = "" ,
870- password = "" ,
871- base_log_folder = self .opensearch_io .base_log_folder ,
872- log_id_template = "{dag_id}-{task_id}-{run_id}-{map_index}-{try_number}" ,
873- )
874-
875- assert "http_auth" not in opensearch_io .client .transport .kwargs
842+ transport_args = handler .client .transport .kwargs
843+ if expect_http_auth :
844+ assert "http_auth" in transport_args
845+ assert transport_args ["http_auth" ] == (username , password )
846+ else :
847+ assert "http_auth" not in handler .client .transport .kwargs
876848
877849
878850class TestOpensearchRemoteLogIOFromConfig :
0 commit comments