Skip to content

Commit

Permalink
regression test: bug #361
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed May 31, 2019
1 parent 2432d20 commit d0f21ec
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from PyQt5.QtWidgets import QWidget, QApplication, QWidgetItem, QSpacerItem, QVBoxLayout, \
QMessageBox, QMainWindow, QTextEdit
from PyQt5.QtCore import Qt
from sqlalchemy.orm import scoped_session, sessionmaker

from tests import factory
from securedrop_client import db, logic
Expand Down Expand Up @@ -1947,6 +1948,55 @@ def test_update_conversation_adds_new_items(mocker, session):
assert cv.conversation_layout.count() == 4


def test_update_conversation_content_updates(mocker, session):
"""
Subsequent calls to update_conversation update the content of the conversation_item
if it has changed.
"""
mock_controller = mocker.MagicMock()
# The controller's session must be a legitimate sqlalchemy session for this test
mock_controller.session = session
source = factory.Source()
session.add(source)
session.flush()

message = factory.Message(filename='2-source-msg.gpg', source=source, content=None)
session.add(message)
session.commit()

cv = ConversationView(source, mock_controller)

cv.conversation_layout.addWidget = mocker.MagicMock()
# this is the MessageWidget that __init__() would return
mock_msg_widget_res = mocker.MagicMock()
# mock MessageWidget so we can inspect the __init__ call to see what content
# is in the widget.
mock_msg_widget = mocker.patch('securedrop_client.gui.widgets.MessageWidget',
return_value=mock_msg_widget_res)

# First call of update_conversation: with null content
cv.update_conversation(cv.source.collection)

# Since the content was None, we should have created the widget
# with the default message (which is the second call_arg).
assert mock_msg_widget.call_args[0][1] == '<Message not yet available>'

# Meanwhile, in another session, we add content to the database for that same message.
engine = session.get_bind()
second_session = scoped_session(sessionmaker(bind=engine))
message = second_session.query(db.Message).one()
expected_content = 'now there is content here!'
message.content = expected_content
second_session.add(message)
second_session.commit()

# Second call of update_conversation
cv.update_conversation(cv.source.collection)

# Check that the widget was updated with the expected content.
assert mock_msg_widget.call_args[0][1] == expected_content


def test_clear_conversation_deletes_items(mocker, homedir):
"""
Calling clear_conversation deletes items from layout
Expand Down

0 comments on commit d0f21ec

Please sign in to comment.