Skip to content

Commit

Permalink
Fix Traceback when undoing changes in URL widget
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen committed Oct 28, 2024
1 parent d7314c9 commit fbedc0b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions spine_items/data_store/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def mergeWith(self, command):
not isinstance(command, UpdateDSURLCommand)
or self._ds_name != command._ds_name
or command._undo_url_is_valid
or set(self._redo_kwargs.keys()).isdisjoint(command._redo_kwargs.keys())
):
return False
diff_key = None
Expand Down
42 changes: 42 additions & 0 deletions tests/data_store/test_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
######################################################################################################################
# Copyright (C) 2017-2022 Spine project consortium
# Copyright Spine Items contributors
# This file is part of Spine Items.
# Spine Items is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
# any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
import unittest
from unittest import mock
from spine_items.data_store.commands import UpdateDSURLCommand


class TestUpdateDSURLCommand(unittest.TestCase):
def test_merging_with_command_that_modifies_same_fields_works(self):
mock_ds = mock.MagicMock()
mock_ds.url.return_value = {"username": "c"}
mock_project = mock.MagicMock()
mock_project.get_item.return_value = mock_ds
command1 = UpdateDSURLCommand("DS 1", False, mock_project, username="ca")
mock_ds.url.return_value = {"username": "ca"}
command2 = UpdateDSURLCommand("DS 1", False, mock_project, username="cat")
self.assertTrue(command1.mergeWith(command2))
command1.redo()
mock_ds.do_update_url.assert_called_once_with(username="cat")

def test_merging_is_rejected_when_commands_modify_different_fields(self):
mock_ds = mock.MagicMock()
mock_ds.url.return_value = {"username": "c", "host": ""}
mock_project = mock.MagicMock()
mock_project.get_item.return_value = mock_ds
command1 = UpdateDSURLCommand("DS 1", False, mock_project, username="ca")
mock_ds.url.return_value = {"username": "ca", "host": ""}
command2 = UpdateDSURLCommand("DS 1", False, mock_project, host="q")
self.assertFalse(command1.mergeWith(command2))


if __name__ == "__main__":
unittest.main()

0 comments on commit fbedc0b

Please sign in to comment.