Skip to content

Commit

Permalink
Refactor remove redundant suffix from action names
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalo-bulnes committed Oct 31, 2022
1 parent 4fcb478 commit b098919
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
4 changes: 2 additions & 2 deletions securedrop_client/gui/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _set_enabled_initial_value(self) -> None:
self._on_selected_conversation_files_changed()


class DeleteSourceAction(QAction):
class DeleteSource(QAction):
"""Use this action to delete the source record."""

def __init__(
Expand Down Expand Up @@ -91,7 +91,7 @@ def trigger(self) -> None:
self._confirmation_dialog.exec()


class DeleteConversationAction(QAction):
class DeleteConversation(QAction):
"""Use this action to delete a source's submissions and replies."""

def __init__(
Expand Down
13 changes: 4 additions & 9 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@
Source,
User,
)
from securedrop_client.gui import conversation
from securedrop_client.gui.actions import (
DeleteConversationAction,
DeleteSourceAction,
DownloadConversation,
)
from securedrop_client.gui import actions, conversation
from securedrop_client.gui.base import SecureQLabel, SvgLabel, SvgPushButton, SvgToggleButton
from securedrop_client.gui.conversation import DeleteConversationDialog
from securedrop_client.gui.source import DeleteSourceDialog
Expand Down Expand Up @@ -3373,13 +3368,13 @@ def __init__(

self.setStyleSheet(self.SOURCE_MENU_CSS)

self.addAction(DownloadConversation(self, self.controller, app_state))
self.addAction(actions.DownloadConversation(self, self.controller, app_state))
self.addAction(
DeleteConversationAction(
actions.DeleteConversation(
self.source, self, self.controller, DeleteConversationDialog, app_state
)
)
self.addAction(DeleteSourceAction(self.source, self, self.controller, DeleteSourceDialog))
self.addAction(actions.DeleteSource(self.source, self, self.controller, DeleteSourceDialog))


class SourceMenuButton(QToolButton):
Expand Down
32 changes: 14 additions & 18 deletions tests/gui/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

from securedrop_client import state
from securedrop_client.db import Source
from securedrop_client.gui.actions import (
DeleteConversationAction,
DeleteSourceAction,
DownloadConversation,
)
from securedrop_client.gui import actions
from securedrop_client.logic import Controller
from tests import factory
from tests.helper import app # noqa: F401


class DeleteConversationActionTest(unittest.TestCase):
class DeleteConversationTest(unittest.TestCase):
def setUp(self):
self._source = factory.Source()
_menu = QMenu()
Expand All @@ -30,7 +26,7 @@ def setUp(self):
def _dialog_constructor(source: Source) -> QDialog:
return self._dialog

self.action = DeleteConversationAction(
self.action = actions.DeleteConversation(
self._source, _menu, self._controller, _dialog_constructor, self._app_state
)

Expand Down Expand Up @@ -79,7 +75,7 @@ def test_deletes_nothing_if_no_conversation_is_selected(self):
assert not self._app_state.remove_conversation_files.called


class DeleteSourceActionTest(unittest.TestCase):
class DeleteSourceTest(unittest.TestCase):
def setUp(self):
self._source = factory.Source()
_menu = QMenu()
Expand All @@ -89,7 +85,7 @@ def setUp(self):
def _dialog_constructor(source: Source) -> QDialog:
return self._dialog

self.action = DeleteSourceAction(self._source, _menu, self._controller, _dialog_constructor)
self.action = actions.DeleteSource(self._source, _menu, self._controller, _dialog_constructor)

def test_deletes_source_when_dialog_accepted(self):
# Accept the confimation dialog from a separate thread.
Expand Down Expand Up @@ -126,7 +122,7 @@ def test_trigger(self):
menu = QMenu()
controller = MagicMock(Controller, api=True)
app_state = state.State()
action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

conversation_id = state.ConversationId("some_conversation")
app_state.selected_conversation = conversation_id
Expand All @@ -139,7 +135,7 @@ def test_requires_authenticated_journalist(self):
menu = QMenu()
controller = mock.MagicMock(Controller, api=None) # no authenticated user
app_state = state.State()
action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

conversation_id = state.ConversationId("some_conversation")
app_state.selected_conversation = conversation_id
Expand All @@ -153,7 +149,7 @@ def test_trigger_downloads_nothing_if_no_conversation_is_selected(self):
menu = QMenu()
controller = MagicMock(Controller, api=True)
app_state = state.State()
action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

action.trigger()
assert controller.download_conversation.not_called
Expand All @@ -162,7 +158,7 @@ def test_gets_disabled_when_no_files_to_download_remain(self):
menu = QMenu()
controller = MagicMock(Controller, api=True)
app_state = state.State()
action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

conversation_id = state.ConversationId(3)
app_state.selected_conversation = conversation_id
Expand All @@ -178,7 +174,7 @@ def test_gets_enabled_when_files_are_available_to_download(self):
menu = QMenu()
controller = MagicMock(Controller, api=True)
app_state = state.State()
action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

conversation_id = state.ConversationId(3)
app_state.selected_conversation = conversation_id
Expand All @@ -200,7 +196,7 @@ def test_gets_initially_disabled_when_file_information_is_available(self):
app_state.add_file(conversation_id, 5)
app_state.file(5).is_downloaded = True

action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

assert not action.isEnabled()

Expand All @@ -214,14 +210,14 @@ def test_gets_initially_enabled_when_file_information_is_available(self):
app_state.add_file(conversation_id, 5)
app_state.file(5).is_downloaded = False

action = DownloadConversation(menu, controller, app_state)
action = actions.DownloadConversation(menu, controller, app_state)

assert action.isEnabled()

def test_does_not_require_state_to_be_defined(self):
menu = QMenu()
controller = MagicMock(Controller, api=True)
action = DownloadConversation(menu, controller, app_state=None)
action = actions.DownloadConversation(menu, controller, app_state=None)

action.setEnabled(False)
assert not action.isEnabled()
Expand All @@ -234,7 +230,7 @@ def test_on_selected_conversation_files_changed_handles_missing_state_gracefully
):
menu = QMenu()
controller = MagicMock(Controller, api=True)
action = DownloadConversation(menu, controller, None)
action = actions.DownloadConversation(menu, controller, None)

action.setEnabled(True)
action._on_selected_conversation_files_changed()
Expand Down

0 comments on commit b098919

Please sign in to comment.