Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a simple shim for status feedback. #65

Merged
merged 3 commits into from
Oct 24, 2018
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
13 changes: 12 additions & 1 deletion securedrop_client/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import logging
from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QDesktopWidget
from PyQt5.QtWidgets import (QMainWindow, QWidget, QVBoxLayout, QDesktopWidget,
QStatusBar)
from PyQt5.QtCore import Qt
from securedrop_client import __version__
from securedrop_client.gui.widgets import (ToolBar, MainView, LoginDialog,
Expand Down Expand Up @@ -70,6 +71,9 @@ def setup(self, controller):
"""
self.controller = controller # Reference the Client logic instance.
self.tool_bar.setup(self, controller)
self.status_bar = QStatusBar(self)
self.setStatusBar(self.status_bar)
self.set_status('Started SecureDrop Client. Please sign in.', 20000)

def autosize_window(self):
"""
Expand Down Expand Up @@ -193,3 +197,10 @@ def show_conversation_for(self, source):
"horrible. She wants the children who survived "
"to find peace. Thanks.")
self.main_view.update_view(conversation)

def set_status(self, message, duration=5000):
"""
Display a status message to the user. Optionally, supply a duration
(in milliseconds), the default value being a duration of 5 seconds.
"""
self.status_bar.showMessage(message, duration)
7 changes: 7 additions & 0 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,10 @@ def logout(self):
"""
self.api = None
self.gui.logout()

def set_status(self, message, duration=5000):
"""
Set a textual status message to be displayed to the user for a certain
duration.
"""
self.gui.set_status(message, duration)
10 changes: 10 additions & 0 deletions tests/gui/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,13 @@ def test_conversation_for():
conv = mock_conview()
assert conv.add_message.call_count > 0
assert conv.add_reply.call_count > 0


def test_set_status():
"""
Ensure the status bar's text is updated.
"""
w = Window()
w.status_bar = mock.MagicMock()
w.set_status('hello', 100)
w.status_bar.showMessage.assert_called_once_with('hello', 100)
11 changes: 11 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ def test_Client_logout(safe_tmpdir):
cl.gui.logout.assert_called_once_with()


def test_Client_set_status(safe_tmpdir):
"""
Ensure the GUI set_status API is called.
"""
mock_gui = mock.MagicMock()
mock_session = mock.MagicMock()
cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
cl.set_status("Hello, World!", 1000)
mock_gui.set_status.assert_called_once_with("Hello, World!", 1000)


PERMISSIONS_CASES = [
{
'should_pass': True,
Expand Down