@@ -33,6 +33,8 @@ def setup_method(self):
3333 self .conn = conn = mock .MagicMock ()
3434 self .conn .host = "host"
3535 self .conn .port = "1000"
36+ self .conn .login = ""
37+ self .conn .password = ""
3638 self .conn .extra_dejson = {}
3739
3840 class PinotAdminHookTest (PinotAdminHook ):
@@ -217,6 +219,8 @@ def setup_method(self):
217219 self .conn = conn = mock .MagicMock ()
218220 self .conn .host = "host"
219221 self .conn .port = "1000"
222+ self .conn .login = ""
223+ self .conn .password = ""
220224 self .conn .conn_type = "http"
221225 self .conn .extra_dejson = {"endpoint" : "query/sql" }
222226 self .cur = mock .MagicMock (rowcount = 0 )
@@ -272,3 +276,191 @@ def test_get_pandas_df(self):
272276 assert column == df .columns [0 ]
273277 for i , item in enumerate (result_sets ):
274278 assert item [0 ] == df .values .tolist ()[i ][0 ]
279+
280+
281+ class TestPinotAdminHookWithAuth :
282+ def setup_method (self ):
283+ self .conn = conn = mock .MagicMock ()
284+ self .conn .host = "host"
285+ self .conn .port = "1000"
286+ self .conn .login = "user"
287+ self .conn .password = "pwd"
288+ self .conn .extra_dejson = {}
289+
290+ class PinotAdminHookTest (PinotAdminHook ):
291+ def get_connection (self , conn_id ):
292+ return conn
293+
294+ self .db_hook = PinotAdminHookTest ()
295+
296+ @mock .patch ("airflow.providers.apache.pinot.hooks.pinot.PinotAdminHook.run_cli" )
297+ def test_add_schema_with_auth (self , mock_run_cli ):
298+ params = ["schema_file" , False ]
299+ self .db_hook .add_schema (* params )
300+ mock_run_cli .assert_called_once_with (
301+ [
302+ "AddSchema" ,
303+ "-user" ,
304+ self .conn .login ,
305+ "-password" ,
306+ self .conn .password ,
307+ "-controllerHost" ,
308+ self .conn .host ,
309+ "-controllerPort" ,
310+ self .conn .port ,
311+ "-schemaFile" ,
312+ params [0 ],
313+ ]
314+ )
315+
316+ @mock .patch ("airflow.providers.apache.pinot.hooks.pinot.PinotAdminHook.run_cli" )
317+ def test_add_table_with_auth (self , mock_run_cli ):
318+ params = ["config_file" , False ]
319+ self .db_hook .add_table (* params )
320+ mock_run_cli .assert_called_once_with (
321+ [
322+ "AddTable" ,
323+ "-user" ,
324+ self .conn .login ,
325+ "-password" ,
326+ self .conn .password ,
327+ "-controllerHost" ,
328+ self .conn .host ,
329+ "-controllerPort" ,
330+ self .conn .port ,
331+ "-filePath" ,
332+ params [0 ],
333+ ]
334+ )
335+
336+ @mock .patch ("airflow.providers.apache.pinot.hooks.pinot.PinotAdminHook.run_cli" )
337+ def test_create_segment_with_auth (self , mock_run_cli ):
338+ params = {
339+ "generator_config_file" : "a" ,
340+ "data_dir" : "b" ,
341+ "segment_format" : "c" ,
342+ "out_dir" : "d" ,
343+ "overwrite" : True ,
344+ "table_name" : "e" ,
345+ "segment_name" : "f" ,
346+ "time_column_name" : "g" ,
347+ "schema_file" : "h" ,
348+ "reader_config_file" : "i" ,
349+ "enable_star_tree_index" : False ,
350+ "star_tree_index_spec_file" : "j" ,
351+ "hll_size" : 9 ,
352+ "hll_columns" : "k" ,
353+ "hll_suffix" : "l" ,
354+ "num_threads" : 8 ,
355+ "post_creation_verification" : True ,
356+ "retry" : 7 ,
357+ }
358+
359+ self .db_hook .create_segment (** params )
360+
361+ mock_run_cli .assert_called_once_with (
362+ [
363+ "CreateSegment" ,
364+ "-user" ,
365+ self .conn .login ,
366+ "-password" ,
367+ self .conn .password ,
368+ "-generatorConfigFile" ,
369+ params ["generator_config_file" ],
370+ "-dataDir" ,
371+ params ["data_dir" ],
372+ "-format" ,
373+ params ["segment_format" ],
374+ "-outDir" ,
375+ params ["out_dir" ],
376+ "-overwrite" ,
377+ params ["overwrite" ],
378+ "-tableName" ,
379+ params ["table_name" ],
380+ "-segmentName" ,
381+ params ["segment_name" ],
382+ "-timeColumnName" ,
383+ params ["time_column_name" ],
384+ "-schemaFile" ,
385+ params ["schema_file" ],
386+ "-readerConfigFile" ,
387+ params ["reader_config_file" ],
388+ "-starTreeIndexSpecFile" ,
389+ params ["star_tree_index_spec_file" ],
390+ "-hllSize" ,
391+ params ["hll_size" ],
392+ "-hllColumns" ,
393+ params ["hll_columns" ],
394+ "-hllSuffix" ,
395+ params ["hll_suffix" ],
396+ "-numThreads" ,
397+ params ["num_threads" ],
398+ "-postCreationVerification" ,
399+ params ["post_creation_verification" ],
400+ "-retry" ,
401+ params ["retry" ],
402+ ]
403+ )
404+
405+ @mock .patch ("airflow.providers.apache.pinot.hooks.pinot.PinotAdminHook.run_cli" )
406+ def test_upload_segment_with_auth (self , mock_run_cli ):
407+ params = ["segment_dir" , False ]
408+ self .db_hook .upload_segment (* params )
409+ mock_run_cli .assert_called_once_with (
410+ [
411+ "UploadSegment" ,
412+ "-user" ,
413+ self .conn .login ,
414+ "-password" ,
415+ self .conn .password ,
416+ "-controllerHost" ,
417+ self .conn .host ,
418+ "-controllerPort" ,
419+ self .conn .port ,
420+ "-segmentDir" ,
421+ params [0 ],
422+ ]
423+ )
424+
425+
426+ class TestPinotDbApiHookWithAuth :
427+ def setup_method (self ):
428+ self .conn = conn = mock .MagicMock ()
429+ self .conn .host = "host"
430+ self .conn .port = "1000"
431+ self .conn .conn_type = "http"
432+ self .conn .login = "user"
433+ self .conn .password = "pwd"
434+ self .conn .extra_dejson = {"endpoint" : "query/sql" }
435+ self .cur = mock .MagicMock (rowcount = 0 )
436+ self .conn .cursor .return_value = self .cur
437+ self .conn .__enter__ .return_value = self .cur
438+ self .conn .__exit__ .return_value = None
439+
440+ class TestPinotDBApiHook (PinotDbApiHook ):
441+ def get_conn (self ):
442+ return conn
443+
444+ def get_connection (self , conn_id ):
445+ return conn
446+
447+ self .db_hook = TestPinotDBApiHook
448+
449+ def test_get_uri_with_auth (self ):
450+ """
451+ Test on getting a pinot connection uri
452+ """
453+ db_hook = self .db_hook ()
454+ assert db_hook .get_uri () == "http://user:pwd@host:1000/query/sql"
455+
456+ def test_get_conn_with_auth (self ):
457+ """
458+ Test on getting a pinot connection
459+ """
460+ conn = self .db_hook ().get_conn ()
461+ assert conn .host == "host"
462+ assert conn .port == "1000"
463+ assert conn .login == "user"
464+ assert conn .password == "pwd"
465+ assert conn .conn_type == "http"
466+ assert conn .extra_dejson .get ("endpoint" ) == "query/sql"
0 commit comments