@@ -954,6 +954,68 @@ def test_find_parameters(self):
954954 assert set (["b" , "foo" , "food" , "time" ]) == reduce (lambda x , y : x | set (y ), result , set ())
955955
956956
957+ def test_get_initial_params_sorting (self ):
958+ """Test that ParameterForm.get_initial_params() sorts parameters correctly"""
959+ from oozie .forms import ParameterForm
960+
961+ # Test data with mixed order parameters
962+ conf_dict = {
963+ 'end_date' : '2024-01-01T10:00:00Z' ,
964+ 'start_date' : '2024-01-01T09:00:00Z' ,
965+ 'oozie.use.system.libpath' : 'true' ,
966+ 'custom_param' : 'value' ,
967+ 'another_param' : 'another_value' ,
968+ 'nominal_time' : '2024-01-01T09:30:00Z'
969+ }
970+
971+ result = ParameterForm .get_initial_params (conf_dict )
972+
973+ # Should be sorted: start_date first, end_date second, then alphabetically
974+ assert len (result ) == 6 , "Expected 6 parameters, got {}" .format (len (result ))
975+ assert result [0 ]['name' ] == 'start_date'
976+ assert result [0 ]['value' ] == '2024-01-01T09:00:00Z'
977+ assert result [1 ]['name' ] == 'end_date'
978+ assert result [1 ]['value' ] == '2024-01-01T10:00:00Z'
979+ assert result [2 ]['name' ] == 'another_param'
980+ assert result [2 ]['value' ] == 'another_value'
981+ assert result [3 ]['name' ] == 'custom_param'
982+ assert result [3 ]['value' ] == 'value'
983+ assert result [4 ]['name' ] == 'nominal_time'
984+ assert result [4 ]['value' ] == '2024-01-01T09:30:00Z'
985+ assert result [5 ]['name' ] == 'oozie.use.system.libpath'
986+ assert result [5 ]['value' ] == 'true'
987+
988+ def test_get_initial_params_edge_cases (self ):
989+ """Test ParameterForm.get_initial_params() with edge cases"""
990+ from oozie .forms import ParameterForm
991+
992+ # Test empty dict
993+ result = ParameterForm .get_initial_params ({})
994+ assert result == []
995+
996+ # Test with oozie parameters (they are included, not filtered out)
997+ conf_dict = {
998+ 'oozie.use.system.libpath' : 'true' ,
999+ 'oozie.some.other.param' : 'value'
1000+ }
1001+ result = ParameterForm .get_initial_params (conf_dict )
1002+ assert len (result ) == 2
1003+ # Should be sorted alphabetically
1004+ assert result [0 ]['name' ] == 'oozie.some.other.param'
1005+ assert result [0 ]['value' ] == 'value'
1006+ assert result [1 ]['name' ] == 'oozie.use.system.libpath'
1007+ assert result [1 ]['value' ] == 'true'
1008+
1009+ # Test with only start_date and end_date
1010+ conf_dict = {
1011+ 'end_date' : '2024-01-01T10:00:00Z' ,
1012+ 'start_date' : '2024-01-01T09:00:00Z'
1013+ }
1014+ result = ParameterForm .get_initial_params (conf_dict )
1015+ assert len (result ) == 2
1016+ assert result [0 ]['name' ] == 'start_date'
1017+ assert result [1 ]['name' ] == 'end_date'
1018+
9571019 def test_find_all_parameters (self ):
9581020 self .wf .data = json .dumps ({'sla' : [
9591021 {'key' : 'enabled' , 'value' : False },
@@ -1955,8 +2017,9 @@ def test_submit_coordinator(self):
19552017
19562018 # Check param popup, SLEEP is set by coordinator so not shown in the popup
19572019 response = self .c .get (reverse ('oozie:submit_coordinator' , args = [coord .id ]))
1958- assert ([{'name' : u'output' , 'value' : '' },
1959- {'name' : u'market' , 'value' : u'US' }
2020+ # Parameters are sorted alphabetically after start_date and end_date
2021+ assert ([{'name' : u'market' , 'value' : u'US' },
2022+ {'name' : u'output' , 'value' : '' }
19602023 ] ==
19612024 response .context [0 ]['params_form' ].initial )
19622025
0 commit comments