33import tempfile
44from unittest import TestCase
55
6- from openhexa .sdk .pipelines .exceptions import PipelineNotFound
6+ from openhexa .sdk .pipelines .exceptions import InvalidParameterError , PipelineNotFound
77from openhexa .sdk .pipelines .runtime import get_pipeline
88
99
@@ -147,6 +147,8 @@ def test_pipeline_with_int_param(self):
147147 "type" : "int" ,
148148 "name" : "Test Param" ,
149149 "default" : 42 ,
150+ "widget" : None ,
151+ "connection" : None ,
150152 "help" : "Param help" ,
151153 "required" : True ,
152154 }
@@ -188,6 +190,8 @@ def test_pipeline_with_multiple_param(self):
188190 "type" : "int" ,
189191 "name" : "Test Param" ,
190192 "default" : [42 ],
193+ "widget" : None ,
194+ "connection" : None ,
191195 "help" : "Param help" ,
192196 "required" : True ,
193197 }
@@ -230,6 +234,8 @@ def test_pipeline_with_dataset(self):
230234 "type" : "dataset" ,
231235 "name" : "Dataset" ,
232236 "default" : None ,
237+ "widget" : None ,
238+ "connection" : None ,
233239 "help" : "Dataset" ,
234240 "required" : False ,
235241 }
@@ -271,6 +277,8 @@ def test_pipeline_with_choices(self):
271277 "type" : "str" ,
272278 "name" : "Test Param" ,
273279 "default" : None ,
280+ "widget" : None ,
281+ "connection" : None ,
274282 "help" : "Param help" ,
275283 "required" : True ,
276284 }
@@ -340,6 +348,8 @@ def test_pipeline_with_bool(self):
340348 "type" : "bool" ,
341349 "name" : "Test Param" ,
342350 "default" : True ,
351+ "widget" : None ,
352+ "connection" : None ,
343353 "help" : "Param help" ,
344354 "required" : True ,
345355 }
@@ -382,6 +392,8 @@ def test_pipeline_with_multiple_parameters(self):
382392 "type" : "int" ,
383393 "name" : "Test Param" ,
384394 "default" : 42 ,
395+ "widget" : None ,
396+ "connection" : None ,
385397 "help" : "Param help" ,
386398 "required" : True ,
387399 },
@@ -392,6 +404,8 @@ def test_pipeline_with_multiple_parameters(self):
392404 "type" : "str" ,
393405 "name" : "Test Param 2" ,
394406 "default" : None ,
407+ "widget" : None ,
408+ "connection" : None ,
395409 "help" : "Param help 2" ,
396410 "required" : True ,
397411 },
@@ -419,3 +433,124 @@ def test_pipeline_with_unsupported_parameter(self):
419433 )
420434 with self .assertRaises (KeyError ):
421435 get_pipeline (tmpdirname )
436+
437+ def test_pipeline_with_connection_parameter (self ):
438+ """The file contains a @pipeline decorator and a @parameter decorator with a connection type."""
439+ with tempfile .TemporaryDirectory () as tmpdirname :
440+ with open (f"{ tmpdirname } /pipeline.py" , "w" ) as f :
441+ f .write (
442+ "\n " .join (
443+ [
444+ "from openhexa.sdk.pipelines import pipeline, parameter" ,
445+ "" ,
446+ "@parameter('dhis_con', name='DHIS2 Connection', type=DHIS2Connection, required=True)" ,
447+ "@parameter('data_element_ids', name='Data Elements id', type=str, widget='dhis2.data_elements.picker', connection='dhis_con', required=True)" ,
448+ "@pipeline('test', 'Test pipeline')" ,
449+ "def test_pipeline():" ,
450+ " pass" ,
451+ "" ,
452+ ]
453+ )
454+ )
455+ pipeline = get_pipeline (tmpdirname )
456+ self .maxDiff = None
457+ self .assertEqual (
458+ pipeline .to_dict (),
459+ {
460+ "code" : "test" ,
461+ "name" : "Test pipeline" ,
462+ "function" : None ,
463+ "tasks" : [],
464+ "parameters" : [
465+ {
466+ "code" : "dhis_con" ,
467+ "type" : "dhis2" ,
468+ "name" : "DHIS2 Connection" ,
469+ "default" : None ,
470+ "multiple" : False ,
471+ "choices" : None ,
472+ "widget" : None ,
473+ "connection" : None ,
474+ "help" : None ,
475+ "required" : True ,
476+ },
477+ {
478+ "code" : "data_element_ids" ,
479+ "type" : "str" ,
480+ "name" : "Data Elements id" ,
481+ "widget" : "dhis2.data_elements.picker" ,
482+ "connection" : "dhis_con" ,
483+ "default" : None ,
484+ "multiple" : False ,
485+ "choices" : None ,
486+ "help" : None ,
487+ "required" : True ,
488+ },
489+ ],
490+ "timeout" : None ,
491+ },
492+ )
493+
494+ def test_pipeline_wit_wrong_connection_parameter (self ):
495+ """The file contains a @pipeline decorator and a @parameter decorator with a non-existing connection type."""
496+ with tempfile .TemporaryDirectory () as tmpdirname :
497+ with open (f"{ tmpdirname } /pipeline.py" , "w" ) as f :
498+ f .write (
499+ "\n " .join (
500+ [
501+ "from openhexa.sdk.pipelines import pipeline, parameter" ,
502+ "" ,
503+ "@parameter('dhis_con', name='DHIS2 Connection', type=DHIS2Connection, required=True)" ,
504+ "@parameter('data_element_ids', name='Data Elements id', type=str, widget='dhis2.data_elements.picker', connection='sds_con', required=True)" ,
505+ "@pipeline('test', 'Test pipeline')" ,
506+ "def test_pipeline():" ,
507+ " pass" ,
508+ "" ,
509+ ]
510+ )
511+ )
512+ with self .assertRaises (InvalidParameterError ):
513+ get_pipeline (tmpdirname )
514+
515+ def test_pipeline_with_widget_without_connection (self ):
516+ """The file contains a @pipeline decorator and a @parameter decorator with a widget parameter field."""
517+ with tempfile .TemporaryDirectory () as tmpdirname :
518+ with open (f"{ tmpdirname } /pipeline.py" , "w" ) as f :
519+ f .write (
520+ "\n " .join (
521+ [
522+ "from openhexa.sdk.pipelines import pipeline, parameter" ,
523+ "" ,
524+ "@parameter('test_field_for_wdiget', name='Widget Param', type=str, widget='custom_picker', help='Param help')" ,
525+ "@pipeline('test', 'Test pipeline')" ,
526+ "def test_pipeline():" ,
527+ " pass" ,
528+ "" ,
529+ ]
530+ )
531+ )
532+ pipeline = get_pipeline (tmpdirname )
533+ self .assertEqual (
534+ pipeline .to_dict (),
535+ {
536+ "code" : "test" ,
537+ "name" : "Test pipeline" ,
538+ "function" : None ,
539+ "tasks" : [],
540+ "parameters" : [
541+ {
542+ "code" : "test_field_for_wdiget" ,
543+ "type" : "str" ,
544+ "name" : "Widget Param" ,
545+ "default" : None ,
546+ "multiple" : False ,
547+ "choices" : None ,
548+ "widget" : "custom_picker" ,
549+ "connection" : None ,
550+ "help" : "Param help" ,
551+ "required" : True ,
552+ }
553+ ],
554+ "timeout" : None ,
555+ },
556+ )
0 commit comments