Skip to content

Commit

Permalink
Add tests for clipboard-purge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence authored and redshiftzero committed Apr 30, 2020
1 parent f763f73 commit 58b8db4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions tests/gui/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,15 @@ def test_logout(mocker):

w.left_pane.set_logged_out.assert_called_once_with()
w.top_pane.set_logged_out.assert_called_once_with()


def test_clear_clipboard(mocker):
"""
Ensure we are clearing the system-level clipboard in the expected manner.
"""
mock_clipboard = mocker.MagicMock()
mocker.patch('securedrop_client.gui.main.QApplication.clipboard',
return_value=mock_clipboard)
w = Window()
w.clear_clipboard()
mock_clipboard.clear.assert_called_once_with()
13 changes: 8 additions & 5 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from PyQt5.QtCore import Qt
from sdclientapi import RequestTimeoutError, ServerConnectionError
from tests import factory
from unittest.mock import call

from securedrop_client import db
from securedrop_client.logic import APICallRunner, Controller, TIME_BETWEEN_SHOWING_LAST_SYNC_MS
Expand Down Expand Up @@ -157,8 +158,8 @@ def test_Controller_login(homedir, config, mocker, session_maker):

def test_Controller_login_offline_mode(homedir, config, mocker):
"""
Ensures user is not authenticated when logging in in offline mode and that the correct windows
are displayed.
Ensures user is not authenticated when logging in in offline mode, that the system
clipboard is cleared, and that the correct windows are subsequently displayed.
"""
co = Controller('http://localhost', mocker.MagicMock(), mocker.MagicMock(), homedir)
co.call_api = mocker.MagicMock()
Expand All @@ -172,7 +173,7 @@ def test_Controller_login_offline_mode(homedir, config, mocker):

assert co.call_api.called is False
assert co.is_authenticated is False
co.gui.show_main_window.assert_called_once_with()
co.gui.assert_has_calls([call.clear_clipboard(), call.show_main_window()])
co.gui.hide_login.assert_called_once_with()
co.update_sources.assert_called_once_with()
co.show_last_sync_timer.start.assert_called_once_with(TIME_BETWEEN_SHOWING_LAST_SYNC_MS)
Expand Down Expand Up @@ -202,7 +203,9 @@ def test_Controller_on_authenticate_failure(homedir, config, mocker, session_mak
def test_Controller_on_authenticate_success(homedir, config, mocker, session_maker,
session):
"""
Ensure the client syncs when the user successfully logs in.
Ensure the client syncs when the user successfully logs in, and that the
system clipboard is cleared prior to display of the main window.
Using the `config` fixture to ensure the config is written to disk.
"""
user = factory.User()
Expand All @@ -221,7 +224,7 @@ def test_Controller_on_authenticate_success(homedir, config, mocker, session_mak
co.resume_queues = mocker.MagicMock()

co.on_authenticate_success(True)

co.gui.assert_has_calls([call.clear_clipboard(), call.show_main_window(user)])
co.api_sync.start.assert_called_once_with(co.api)
co.api_job_queue.start.assert_called_once_with(co.api)
assert co.is_authenticated
Expand Down

0 comments on commit 58b8db4

Please sign in to comment.