Skip to content

Commit

Permalink
updated tests on main conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
heartsucker committed Jan 4, 2019
1 parent 429448b commit 1b7cb73
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions tests/gui/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def test_conversation_for(mocker):
w = Window('mock')
w.controller = mocker.MagicMock()
w.main_view = mocker.MagicMock()
mock_conview = mocker.MagicMock()
mock_source = mocker.MagicMock()
mock_source.journalistic_designation = 'Testy McTestface'
mock_file = mocker.MagicMock()
Expand All @@ -196,16 +195,30 @@ def test_conversation_for(mocker):
mock_reply.filename = '3-my-source-reply.gpg'
mock_source.collection = [mock_file, mock_message, mock_reply]

mocker.patch('securedrop_client.gui.main.ConversationView', mock_conview)
mocked_add_message = mocker.patch('securedrop_client.gui.main.ConversationView.add_message')
mocked_add_reply = mocker.patch('securedrop_client.gui.main.ConversationView.add_reply')
mocked_add_file = mocker.patch('securedrop_client.gui.main.ConversationView.add_file')
mocker.patch('securedrop_client.gui.main.QVBoxLayout')
mocker.patch('securedrop_client.gui.main.QWidget')

w.show_conversation_for(mock_source)
conv = mock_conview()

assert conv.add_message.call_count > 0
assert conv.add_reply.call_count > 0
assert conv.add_file.call_count > 0
assert mocked_add_message.call_count > 0
assert mocked_add_reply.call_count > 0
assert mocked_add_file.call_count > 0

# check that showing the conversation a second time doesn't break anything

# use new mocks to check the count again
mocked_add_message = mocker.patch('securedrop_client.gui.main.ConversationView.add_message')
mocked_add_reply = mocker.patch('securedrop_client.gui.main.ConversationView.add_reply')
mocked_add_file = mocker.patch('securedrop_client.gui.main.ConversationView.add_file')

w.show_conversation_for(mock_source)

assert mocked_add_message.call_count > 0
assert mocked_add_reply.call_count > 0
assert mocked_add_file.call_count > 0


def test_conversation_pending_message(mocker):
Expand All @@ -217,7 +230,6 @@ def test_conversation_pending_message(mocker):
w.controller = mocker.MagicMock()
w.main_view = mocker.MagicMock()
w._add_item_content_or = mocker.MagicMock()
mock_conview = mocker.MagicMock()
mock_source = mocker.MagicMock()
mock_source.journalistic_designation = 'Testy McTestface'

Expand All @@ -229,15 +241,14 @@ def test_conversation_pending_message(mocker):

mock_source.collection = [submission]

mocker.patch('securedrop_client.gui.main.ConversationView', mock_conview)
mocked_add_message = mocker.patch('securedrop_client.gui.main.ConversationView.add_message')
mocker.patch('securedrop_client.gui.main.QVBoxLayout')
mocker.patch('securedrop_client.gui.main.QWidget')

w.show_conversation_for(mock_source)
conv = mock_conview()

assert conv.add_message.call_count == 1
assert conv.add_message.call_args == mocker.call("<Message not yet downloaded>")
assert mocked_add_message.call_count == 1
assert mocked_add_message.call_args == mocker.call("<Message not yet downloaded>")


def test_set_status(mocker):
Expand Down

0 comments on commit 1b7cb73

Please sign in to comment.