Skip to content

Commit

Permalink
Tests pass... Feedback required.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoll authored and sssoleileraaa committed Jan 22, 2020
1 parent 1fe8ba5 commit 0914d92
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
12 changes: 7 additions & 5 deletions securedrop_client/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ def get_local_sources(session: Session) -> List[Source]:
return session.query(Source).all()


def delete_local_source_by_uuid(session: Session, uuid: str) -> Source:
def delete_local_source_by_uuid(session: Session, uuid: str) -> None:
"""
Return the source with the referenced UUID.
Delete the source with the referenced UUID.
"""
source = session.query(Source).filter_by(uuid=uuid)
session.delete(source)
session.commit()
source = session.query(Source).filter_by(uuid=uuid).one_or_none()
if source:
session.delete(source)
session.commit()
logger.info("Deleted source with UUID {} from local database.".format(uuid))


def get_local_messages(session: Session) -> List[Message]:
Expand Down
8 changes: 5 additions & 3 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,10 +1271,12 @@ def test_Controller_on_delete_source_success(homedir, config, mocker, session_ma
Using the `config` fixture to ensure the config is written to disk.
'''
mock_gui = mocker.MagicMock()
storage = mocker.patch('securedrop_client.logic.storage')
co = Controller('http://localhost', mock_gui, session_maker, homedir)
co.sync_api = mocker.MagicMock()
co.on_delete_source_success(True)
co.sync_api.assert_called_with()
co.update_sources = mocker.MagicMock()
co.on_delete_source_success("uuid")
storage.delete_local_source_by_uuid.assert_called_once_with(co.session, "uuid")
assert co.update_sources.call_count == 1


def test_Controller_on_delete_source_failure(homedir, config, mocker, session_maker):
Expand Down
18 changes: 17 additions & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
delete_single_submission_or_reply_on_disk, rename_file, get_local_files, find_new_files, \
source_exists, set_message_or_reply_content, mark_as_downloaded, mark_as_decrypted, get_file, \
get_message, get_reply, update_and_get_user, update_missing_files, mark_as_not_downloaded, \
mark_all_pending_drafts_as_failed
mark_all_pending_drafts_as_failed, delete_local_source_by_uuid

from securedrop_client import db
from tests import factory
Expand Down Expand Up @@ -72,6 +72,22 @@ def test_get_local_sources(mocker):
mock_session.query.assert_called_once_with(securedrop_client.db.Source)


def test_delete_local_source_by_uuid(mocker):
"""
Delete the referenced source in the session.
"""
mock_session = mocker.MagicMock()
source = make_remote_source()
mock_session.query().filter_by().one_or_none.return_value = source
mock_session.query.reset_mock()
delete_local_source_by_uuid(mock_session, "uuid")
mock_session.query.assert_called_once_with(securedrop_client.db.Source)
mock_session.query().filter_by.assert_called_once_with(uuid="uuid")
assert mock_session.query().filter_by().one_or_none.call_count == 1
mock_session.delete.assert_called_once_with(source)
mock_session.commit.assert_called_once_with()


def test_get_local_messages(mocker):
"""
At this moment, just return all messages.
Expand Down

0 comments on commit 0914d92

Please sign in to comment.