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 committed Apr 30, 2020
1 parent 575a6b3 commit 8ab83da
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):

This comment has been minimized.

Copy link
@eloquence

eloquence Apr 30, 2020

Author Member

FWIW, I'm not sure how much value a test like this really adds other than getting us to 100% coverage (that's why I also added the logic tests), please let me know if you see a more useful approach for this one. :)

"""
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 @@ -9,6 +9,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 @@ -154,8 +155,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 @@ -169,7 +170,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 @@ -199,7 +200,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 @@ -218,7 +221,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 8ab83da

Please sign in to comment.