Skip to content

Commit be06cfb

Browse files
bjornalmHarshg999
andauthored
[oozie]: fix random order of start end time fields (#4293)
* [oozie]: fix random order of start end time fields * [oozie] update test to reflect sorted parameters --------- Co-authored-by: Harsh Gupta <[email protected]>
1 parent e6ba1ba commit be06cfb

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

apps/oozie/src/oozie/forms.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
import sys
1918
import logging
2019
from builtins import object
2120
from datetime import datetime, timedelta
2221
from functools import partial
2322
from time import mktime, struct_time
2423

2524
from django import forms
26-
from django.core.exceptions import ValidationError
2725
from django.forms.widgets import TextInput
2826
from django.utils.translation import gettext_lazy as _t
2927

@@ -86,6 +84,18 @@ class ParameterForm(forms.Form):
8684
@staticmethod
8785
def get_initial_params(conf_dict):
8886
params = [key for key in list(conf_dict.keys()) if key not in ParameterForm.NON_PARAMETERS]
87+
88+
# Sort parameters: start_date first, end_date second, then alphabetically
89+
def param_sort_key(name):
90+
if name == 'start_date':
91+
return (0, name)
92+
elif name == 'end_date':
93+
return (1, name)
94+
else:
95+
return (2, name)
96+
97+
params.sort(key=param_sort_key)
98+
8999
return [{'name': name, 'value': conf_dict[name]} for name in params]
90100

91101
@staticmethod

apps/oozie/src/oozie/tests.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)