forked from openlp/openlp
added test; refactor
This commit is contained in:
parent
cf798e73d5
commit
6c08a80bfd
@ -244,10 +244,10 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties)
|
||||
self.primary_push_button.setChecked(False)
|
||||
self.alternate_push_button.setChecked(False)
|
||||
else:
|
||||
if action.defaultShortcuts:
|
||||
primary_label_text = action.defaultShortcuts[0].toString()
|
||||
if len(action.defaultShortcuts) == 2:
|
||||
alternate_label_text = action.defaultShortcuts[1].toString()
|
||||
if action.default_shortcuts:
|
||||
primary_label_text = action.default_shortcuts[0].toString()
|
||||
if len(action.default_shortcuts) == 2:
|
||||
alternate_label_text = action.default_shortcuts[1].toString()
|
||||
shortcuts = self._action_shortcuts(action)
|
||||
# We do not want to loose pending changes, that is why we have to keep the text when, this function has not
|
||||
# been triggered by a signal.
|
||||
@ -292,7 +292,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties)
|
||||
self._adjust_button(self.alternate_push_button, False, text='')
|
||||
for category in self.action_list.categories:
|
||||
for action in category.actions:
|
||||
self.changed_actions[action] = action.defaultShortcuts
|
||||
self.changed_actions[action] = action.default_shortcuts
|
||||
self.refresh_shortcut_list()
|
||||
|
||||
def on_default_radio_button_clicked(self, toggled):
|
||||
@ -306,7 +306,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties)
|
||||
if action is None:
|
||||
return
|
||||
temp_shortcuts = self._action_shortcuts(action)
|
||||
self.changed_actions[action] = action.defaultShortcuts
|
||||
self.changed_actions[action] = action.default_shortcuts
|
||||
self.refresh_shortcut_list()
|
||||
primary_button_text = ''
|
||||
alternate_button_text = ''
|
||||
@ -357,8 +357,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties)
|
||||
return
|
||||
shortcuts = self._action_shortcuts(action)
|
||||
new_shortcuts = []
|
||||
if action.defaultShortcuts:
|
||||
new_shortcuts.append(action.defaultShortcuts[0])
|
||||
if action.default_shortcuts:
|
||||
new_shortcuts.append(action.default_shortcuts[0])
|
||||
# We have to check if the primary default shortcut is available. But we only have to check, if the action
|
||||
# has a default primary shortcut (an "empty" shortcut is always valid and if the action does not have a
|
||||
# default primary shortcut, then the alternative shortcut (not the default one) will become primary
|
||||
@ -383,8 +383,8 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties)
|
||||
new_shortcuts = []
|
||||
if shortcuts:
|
||||
new_shortcuts.append(shortcuts[0])
|
||||
if len(action.defaultShortcuts) == 2:
|
||||
new_shortcuts.append(action.defaultShortcuts[1])
|
||||
if len(action.default_shortcuts) == 2:
|
||||
new_shortcuts.append(action.default_shortcuts[1])
|
||||
if len(new_shortcuts) == 2:
|
||||
if not self._validiate_shortcut(action, new_shortcuts[1]):
|
||||
return
|
||||
|
@ -69,6 +69,7 @@ class CategoryActionList(object):
|
||||
"""
|
||||
Implement the __getitem__() method to make this class a dictionary type
|
||||
"""
|
||||
assert False
|
||||
for weight, action in self.actions:
|
||||
if action.text() == key:
|
||||
return action
|
||||
@ -78,7 +79,10 @@ class CategoryActionList(object):
|
||||
"""
|
||||
Implement the __contains__() method to make this class a dictionary type
|
||||
"""
|
||||
return item in self
|
||||
for weight, action in self.actions:
|
||||
if action.text() == item:
|
||||
return True
|
||||
return False
|
||||
|
||||
def __len__(self):
|
||||
"""
|
||||
@ -107,10 +111,7 @@ class CategoryActionList(object):
|
||||
"""
|
||||
Implement the has_key() method to make this class a dictionary type
|
||||
"""
|
||||
for weight, action in self.actions:
|
||||
if action.text() == key:
|
||||
return True
|
||||
return False
|
||||
return key in self
|
||||
|
||||
def append(self, name):
|
||||
"""
|
||||
@ -270,7 +271,7 @@ class ActionList(object):
|
||||
settings = Settings()
|
||||
settings.beginGroup('shortcuts')
|
||||
# Get the default shortcut from the config.
|
||||
action.defaultShortcuts = settings.get_default_value(action.objectName())
|
||||
action.default_shortcuts = settings.get_default_value(action.objectName())
|
||||
if weight is None:
|
||||
self.categories[category].actions.append(action)
|
||||
else:
|
||||
|
@ -32,9 +32,11 @@ Package to test the openlp.core.utils.actions package.
|
||||
from unittest import TestCase
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
from mock import MagicMock
|
||||
|
||||
from openlp.core.common import Settings
|
||||
from openlp.core.utils import ActionList
|
||||
from openlp.core.utils.actions import CategoryActionList
|
||||
from tests.helpers.testmixin import TestMixin
|
||||
|
||||
|
||||
@ -149,3 +151,63 @@ class TestActionList(TestCase, TestMixin):
|
||||
# THEN: Both action should keep their shortcuts.
|
||||
assert len(action3.shortcuts()) == 2, 'The action should have two shortcut assigned.'
|
||||
assert len(action_with_same_shortcuts3.shortcuts()) == 2, 'The action should have two shortcuts assigned.'
|
||||
|
||||
|
||||
class TestCategoryActionList(TestCase):
|
||||
def setUp(self):
|
||||
"""
|
||||
"""
|
||||
self.added_action = MagicMock()
|
||||
self.added_action.text = MagicMock('first')
|
||||
self.not_added_action = MagicMock('second')
|
||||
self.not_added_action.text = MagicMock()
|
||||
self.list = CategoryActionList()
|
||||
self.list.add(self.added_action, 10)
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
|
||||
"""
|
||||
del self.list
|
||||
|
||||
def len_test(self):
|
||||
"""
|
||||
Test the __len__ method
|
||||
"""
|
||||
# GIVEN: The list.
|
||||
|
||||
# WHEN: Check the length
|
||||
length = len(self.list)
|
||||
|
||||
# THEN:
|
||||
self.assertEqual(length, 1, "The length should be 1.")
|
||||
|
||||
# GIVEN: A list with an item.
|
||||
self.list.append(self.not_added_action)
|
||||
|
||||
# WHEN: Check the length.
|
||||
length = len(self.list)
|
||||
|
||||
# THEN:
|
||||
self.assertEqual(length, 2, "The length should be 2.")
|
||||
|
||||
def remove_test(self):
|
||||
"""
|
||||
Test the remove() method
|
||||
"""
|
||||
# GIVEN: The list
|
||||
|
||||
# WHEN: Delete an item from the list.
|
||||
self.list.remove(self.added_action)
|
||||
|
||||
# THEN: Now the element should not be in the list anymore.
|
||||
self.assertFalse(self.added_action in self.list)
|
||||
|
||||
def contains_test(self):
|
||||
"""
|
||||
Test the __contains__() method
|
||||
"""
|
||||
# GIVEN: The list.
|
||||
# WHEN: Do nothing.
|
||||
# THEN: A not added item should not be in the list.
|
||||
self.assertFalse(self.not_added_action in self.list)
|
Loading…
Reference in New Issue
Block a user