Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions mslib/msui/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def set_noneditable_items(self, parent):
index = self.json_model.index(r, 0, parent)
item = self.json_model.itemFromIndex(index)
item.setEditable(False)
if item.text() in mss_default.fixed_dict_options:
if item.text() in mss_default.fixed_dict_options + mss_default.fixed_list_options:
self.set_noneditable_items(index)
if item.text() in mss_default.config_descriptions:
item.setData(mss_default.config_descriptions[item.text()], QtCore.Qt.ToolTipRole)
Expand All @@ -243,7 +243,8 @@ def tree_selection_changed(self, selected, deselected):
if not index.parent().isValid():
move = True
root_index = get_root_index(index)
if root_index.data() not in mss_default.fixed_dict_options + mss_default.key_value_options:
if (root_index.data() not in mss_default.fixed_dict_options + mss_default.key_value_options +
mss_default.fixed_list_options):
add, move = True, True

# display error message if key has invalid values
Expand All @@ -265,8 +266,8 @@ def tree_selection_changed(self, selected, deselected):
restore_defaults = True
for index in selection:
index = get_root_index(index)
if index.data() not in mss_default.fixed_dict_options + mss_default.key_value_options \
and self.proxy_model.rowCount(index) > 0:
if index.data() not in mss_default.fixed_dict_options + mss_default.key_value_options \
+ mss_default.fixed_list_options and self.proxy_model.rowCount(index) > 0:
remove = True
break

Expand Down
26 changes: 16 additions & 10 deletions mslib/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ class MSUIDefaultConfig:

# Dictionary options with fixed key/value pairs
fixed_dict_options = ["layout", "wms_prefetch", "topview", "sideview", "linearview"]
# List options with fixed length
fixed_list_options = ["MSCOLAB_timeout", ]

# Fixed key/value pair options
key_value_options = [
Expand Down Expand Up @@ -366,7 +368,7 @@ class MSUIDefaultConfig:
"new_flighttrack_template": ["new-location"],
"gravatar_ids": ["[email protected]"],
"WMS_preload": ["https://wms-preload-url.com"],
"MSCOLAB_timeout": [[2, 10]],
"MSCOLAB_timeout": [0, 0],
"automated_plotting_flights": [["", "", "", "", "", ""]],
"automated_plotting_hsecs": [["http://www.your-wms-server.de", "", "", ""]],
"automated_plotting_vsecs": [["http://www.your-wms-server.de", "", "", ""]],
Expand Down Expand Up @@ -418,6 +420,7 @@ class MSUIDefaultConfig:
"__dict__",
"__weakref__",
"fixed_dict_options",
"fixed_list_options",
"dict_option_structure",
"list_option_structure",
"key_value_options",
Expand Down Expand Up @@ -597,7 +600,7 @@ def merge_dict(existing_dict, new_dict):
new_dict -- Dict with new values
"""
# Check if dictionary options with fixed key/value pairs match data types from default
for key in MSUIDefaultConfig.fixed_dict_options:
for key in MSUIDefaultConfig.fixed_dict_options + MSUIDefaultConfig.fixed_list_options:
if key in new_dict:
existing_dict[key] = compare_data(
existing_dict[key], new_dict[key]
Expand All @@ -615,6 +618,8 @@ def merge_dict(existing_dict, new_dict):
for option_key in new_dict[key]:
for dos_key_key in dos[key]:
data, match = compare_data(dos[key][dos_key_key], new_dict[key][option_key])
if key in MSUIDefaultConfig.fixed_list_options:
match = len(dos[key][dos_key_key]) == len(new_dict[key][option_key])
if match:
temp_data[option_key] = new_dict[key][option_key]
break
Expand All @@ -626,14 +631,15 @@ def merge_dict(existing_dict, new_dict):
for key in los:
if key in new_dict:
temp_data = []
for i in range(len(new_dict[key])):
for los_key_item in los[key]:
data, match = compare_data(los_key_item, new_dict[key][i])
if match:
temp_data.append(data)
break
if temp_data != []:
existing_dict[key] = temp_data
if key not in MSUIDefaultConfig.fixed_list_options:
for i in range(len(new_dict[key])):
for los_key_item in los[key]:
data, match = compare_data(los_key_item, new_dict[key][i])
if match:
temp_data.append(data)
break
if temp_data != []:
existing_dict[key] = temp_data

# Check if options with fixed key/value pair structure match data types from default
for key in MSUIDefaultConfig.key_value_options:
Expand Down
41 changes: 35 additions & 6 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from mslib.mscolab.models import Permission, User
from mslib.msui.flighttrack import WaypointsTableModel
from PyQt5 import QtCore, QtTest, QtWidgets
from mslib.utils.config import read_config_file, config_loader, modify_config_file
from mslib.utils.config import MSUIDefaultConfig, read_config_file, config_loader, modify_config_file
from tests.utils import create_msui_settings_file, ExceptionMock
from mslib.msui import msui
from mslib.msui import mscolab
Expand Down Expand Up @@ -298,13 +298,42 @@ def setup(self, qtbot, mscolab_app, mscolab_server):
# close all hanging operation option windows
self.window.mscolab.close_external_windows()

@pytest.mark.xfail(reason="https://github.com/Open-MSS/MSS/issues/2716", strict=True)
def test_modify_mscolab_timeout(self, qtbot):
data = {"MSCOLAB_timeout": [5, 10]}
@pytest.mark.parametrize("input_list, expected_list", [([5, 12], [5, 12]),
([5.1, 12.1], MSUIDefaultConfig.MSCOLAB_timeout),
([1, 2, 3, 4], MSUIDefaultConfig.MSCOLAB_timeout),
([4], MSUIDefaultConfig.MSCOLAB_timeout)
])
def test_modify_fixed_list_options(self, input_list, expected_list, qtbot):
data = {"MSCOLAB_timeout": input_list}
modify_config_file(data)
self.window.open_config_editor()
# the assert fails because last_saved returns [[2, 10], [2, 10]]
assert self.window.config_editor.last_saved["MSCOLAB_timeout"] == data["MSCOLAB_timeout"]
assert self.window.config_editor.last_saved["MSCOLAB_timeout"] == expected_list

@pytest.mark.parametrize("input_dict, expected_dict", [({"validtime_fwd": 0, "validtime_bck": 1,
"level_up": 2, "level_down": 3},
{"validtime_fwd": 0, "validtime_bck": 1,
"level_up": 2, "level_down": 3}),
({"validtime_fwd": 0.0, "validtime_bck": 1.0,
"level_up": 2.0, "level_down": 3.0},
MSUIDefaultConfig.wms_prefetch),
({"validtime_fwd": 0, "validtime_bck": 1},
MSUIDefaultConfig.wms_prefetch)
])
def test_modify_fixed_dict_options(self, input_dict, expected_dict, qtbot):
data = {"wms_prefetch": input_dict}
modify_config_file(data)
self.window.open_config_editor()
assert self.window.config_editor.last_saved["wms_prefetch"] == expected_dict

@pytest.mark.parametrize("input_value, expected_value", [(20, 20),
((1, 2), MSUIDefaultConfig.num_labels),
(1.3435, MSUIDefaultConfig.num_labels)
])
def test_modify_value(self, input_value, expected_value, qtbot):
data = {"num_labels": input_value}
modify_config_file(data)
self.window.open_config_editor()
assert self.window.config_editor.last_saved["num_labels"] == expected_value

def test_activate_operation(self, qtbot):
self._connect_to_mscolab(qtbot)
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_milestone_url(self):
with urlopen(self.window.milestone_url) as f:
text = f.read().decode("utf-8")
expected_version = __version__
pattern = rf'value="is:closed milestone:{re.escape(expected_version)}"'
pattern = rf'value="is:closed milestone:{re.escape(expected_version)} "'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems gh has changed the content.

The test is then very fragile and needs a better solution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert re.search(pattern, text), f"Expected milestone format not found: {expected_version}"


Expand Down
Loading