Skip to content

Commit

Permalink
inject homedir for pulling data on update
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed Jan 6, 2019
1 parent 91ae6ed commit cc8f6a4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
3 changes: 1 addition & 2 deletions securedrop_client/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
ConversationView,
SourceProfileShortWidget)
from securedrop_client.resources import load_icon
from securedrop_client.storage import get_data

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -177,7 +176,7 @@ def show_conversation_for(self, source):
conversation_container = self.conversations.get(source.uuid, None)

if conversation_container is None:
conversation = ConversationView(source, parent=self)
conversation = ConversationView(source, self.sdc_home, parent=self)
conversation.setup(self.controller)

conversation_container = QWidget()
Expand Down
6 changes: 4 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
QMessageBox, QToolButton

from securedrop_client.resources import load_svg, load_image
from securedrop_client.storage import get_data
from securedrop_client.utils import humanize_filesize

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -612,9 +613,10 @@ class ConversationView(QWidget):
Renders a conversation.
"""

def __init__(self, source_db_object, parent=None):
def __init__(self, source_db_object, sdc_home: str, parent=None):
super().__init__(parent)
self.source = source_db_object
self.sdc_home = sdc_home

self.container = QWidget()
self.conversation_layout = QVBoxLayout()
Expand Down Expand Up @@ -667,7 +669,7 @@ def add_item_content_or(self, adder, item, default):
if item.is_downloaded is False:
adder(default)
else:
adder(item.content)
adder(get_data(self.sdc_home, item.filename))

def setup(self, controller):
"""
Expand Down
6 changes: 1 addition & 5 deletions securedrop_client/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,7 @@ def on_file_downloaded(self, result, current_object):
# Now that download and decrypt are done, mark the file as such.
storage.mark_file_as_downloaded(file_uuid, self.session)

# Refresh the current source conversation, bearing in mind
# that the user may have navigated to another source.
self.gui.show_conversation_for(self.gui.current_source)
self.set_status(
'Finished downloading {}'.format(current_object.filename))
self.set_status('Finished downloading {}'.format(current_object.filename))
else: # The file did not download properly.
# Update the UI in some way to indicate a failure state.
self.set_status("The file download failed. Please try again.")
Expand Down
28 changes: 14 additions & 14 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,44 +680,44 @@ def test_FileWidget_mousePressEvent_open(mocker):
fw.controller.on_file_open.assert_called_once_with(submission)


def test_ConversationView_init(mocker):
def test_ConversationView_init(mocker, homedir):
"""
Ensure the conversation view has a layout to add widgets to.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
assert isinstance(cv.conversation_layout, QVBoxLayout)


def test_ConversationView_setup(mocker):
def test_ConversationView_setup(mocker, homedir):
"""
Ensure the controller is set
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
mock_controller = mocker.MagicMock()
cv.setup(mock_controller)
assert cv.controller == mock_controller


def test_ConversationView_move_to_bottom(mocker):
def test_ConversationView_move_to_bottom(mocker, homedir):
"""
Check the signal handler sets the correct value for the scrollbar to be
the maximum possible value.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
cv.scroll = mocker.MagicMock()
cv.move_to_bottom(0, 6789)
cv.scroll.verticalScrollBar().setValue.assert_called_once_with(6789)


def test_ConversationView_add_message(mocker):
def test_ConversationView_add_message(mocker, homedir):
"""
Adding a message results in a new MessageWidget added to the layout.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
cv.controller = mocker.MagicMock()
cv.conversation_layout = mocker.MagicMock()

Expand All @@ -728,12 +728,12 @@ def test_ConversationView_add_message(mocker):
assert isinstance(cal[0][0][0], MessageWidget)


def test_ConversationView_add_reply(mocker):
def test_ConversationView_add_reply(mocker, homedir):
"""
Adding a reply results in a new ReplyWidget added to the layout.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
cv.controller = mocker.MagicMock()
cv.conversation_layout = mocker.MagicMock()

Expand All @@ -744,13 +744,13 @@ def test_ConversationView_add_reply(mocker):
assert isinstance(cal[0][0][0], ReplyWidget)


def test_ConversationView_add_downloaded_file(mocker):
def test_ConversationView_add_downloaded_file(mocker, homedir):
"""
Adding a file results in a new FileWidget added to the layout with the
proper QLabel.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
cv.controller = mocker.MagicMock()
cv.conversation_layout = mocker.MagicMock()

Expand All @@ -769,13 +769,13 @@ def test_ConversationView_add_downloaded_file(mocker):
assert isinstance(cal[0][0][0], FileWidget)


def test_ConversationView_add_not_downloaded_file(mocker):
def test_ConversationView_add_not_downloaded_file(mocker, homedir):
"""
Adding a file results in a new FileWidget added to the layout with the
proper QLabel.
"""
mocked_source = mocker.MagicMock()
cv = ConversationView(mocked_source)
cv = ConversationView(mocked_source, homedir)
cv.controller = mocker.MagicMock()
cv.conversation_layout = mocker.MagicMock()

Expand Down
3 changes: 1 addition & 2 deletions tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,7 @@ def test_Client_update_conversation_views(homedir, config, mocker):
cl = Client('http://localhost', mock_gui, mock_session, homedir)
cl.update_conversation_views()
mock_session.refresh.assert_called_with(mock_gui.current_source)
mock_gui.show_conversation_for.assert_called_once_with(
mock_gui.current_source)
mock_gui.show_conversation_for.assert_called_once_with(mock_gui.current_source)


def test_Client_unstars_a_source_if_starred(homedir, config, mocker):
Expand Down

0 comments on commit cc8f6a4

Please sign in to comment.