Skip to content

Commit

Permalink
add test for invalidate_token
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed Feb 3, 2020
1 parent ebc8df7 commit 220995c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _submit_download_job(self,
if object_type == db.Reply:
job = ReplyDownloadJob(
uuid, self.data_dir, self.gpg
) # type: Union[ReplyDownloadJob, MessageDownloadJob, FileDownloadJob]
) # type: Union[ReplyDownloadJob, MessageDownloadJob, FileDownloadJob]
job.success_signal.connect(self.on_reply_download_success, type=Qt.QueuedConnection)
job.failure_signal.connect(self.on_reply_download_failure, type=Qt.QueuedConnection)
elif object_type == db.Message:
Expand Down
40 changes: 40 additions & 0 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,46 @@ def test_Controller_on_update_star_failed(homedir, config, mocker, session_maker
mock_gui.update_error_status.assert_called_once_with('Failed to update star.')


def test_Controller_invalidate_token(mocker, homedir, session_maker):
'''
Ensure the controller's api token is set to None.
'''
co = Controller('http://localhost', mocker.MagicMock(), session_maker, homedir)
co.api = 'not None'

co.invalidate_token()

assert co.api is None


def test_Controller_logout_with_pending_replies(mocker, session_maker, homedir, reply_status_codes):
'''
Ensure draft reply fails on logout and that the reply_failed signal is emitted.
'''
co = Controller('http://localhost', mocker.MagicMock(), session_maker, homedir)
co.api_job_queue = mocker.MagicMock()
co.api_job_queue.logout = mocker.MagicMock()
co.call_api = mocker.MagicMock()
co.reply_failed = mocker.MagicMock()

source = factory.Source()
session = session_maker()
pending_status = session.query(db.ReplySendStatus).filter_by(
name=db.ReplySendStatusCodes.PENDING.value).one()
failed_status = session.query(db.ReplySendStatus).filter_by(
name=db.ReplySendStatusCodes.FAILED.value).one()
pending_draft_reply = factory.DraftReply(source=source, send_status=pending_status)
session.add(source)
session.add(pending_draft_reply)

co.logout()

for draft in session.query(db.DraftReply).all():
assert draft.send_status == failed_status

co.reply_failed.emit.assert_called_once_with(pending_draft_reply.uuid)


def test_Controller_logout_with_no_api(homedir, config, mocker, session_maker):
'''
Ensure we don't attempt to make an api call to logout when the api has been set to None
Expand Down

0 comments on commit 220995c

Please sign in to comment.