コード例 #1
0
def test_conversation_pending_message():
    """
    Test that a conversation with a message that's not yet downloaded
    shows the right placeholder text
    """
    w = Window()
    w.controller = mock.MagicMock()
    w.main_view = mock.MagicMock()
    w._add_item_content_or = mock.MagicMock()
    mock_conview = mock.MagicMock()
    mock_source = mock.MagicMock()
    mock_source.journalistic_designation = 'Testy McTestface'

    submission = Submission(source=mock_source,
                            uuid="test",
                            size=123,
                            filename="test.msg.gpg",
                            download_url='http://test/test')

    submission.is_downloaded = False

    mock_source.collection = [submission]

    with mock.patch('securedrop_client.gui.main.ConversationView',
                    mock_conview):
        w.show_conversation_for(mock_source)
        conv = mock_conview()

        # once for source name, once for message
        assert conv.add_message.call_count == 2
        assert conv.add_message.call_args == \
            mock.call("<Message not yet downloaded>")
コード例 #2
0
def test_conversation_pending_message(mocker):
    """
    Test that a conversation with a message that's not yet downloaded
    shows the right placeholder text
    """
    w = Window('mock')
    w.controller = mocker.MagicMock()
    w.main_view = mocker.MagicMock()
    w._add_item_content_or = mocker.MagicMock()
    mock_source = mocker.MagicMock()
    mock_source.journalistic_designation = 'Testy McTestface'

    msg_uuid = str(uuid4())
    submission = Submission(source=mock_source,
                            uuid=msg_uuid,
                            size=123,
                            filename="test.msg.gpg",
                            download_url='http://test/test')

    submission.is_downloaded = False

    mock_source.collection = [submission]

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

    w.show_conversation_for(mock_source)

    assert mocked_add_message.call_count == 1
    assert mocked_add_message.call_args == mocker.call(
        msg_uuid, "<Message not yet downloaded>")
コード例 #3
0
def test_show_sources(mocker):
    """
    Ensure the sources list is passed to the main view to be updated.
    """
    w = Window()
    w.main_view = mocker.MagicMock()
    w.show_sources([1, 2, 3])
    w.main_view.show_sources.assert_called_once_with([1, 2, 3])
コード例 #4
0
def test_show_sources():
    """
    Ensure the sources list is passed to the source list widget to be updated.
    """
    w = Window()
    w.main_view = mock.MagicMock()
    w.show_sources([1, 2, 3])
    w.main_view.source_list.update.assert_called_once_with([1, 2, 3])
コード例 #5
0
def test_show_sync_no_sync(mocker):
    """
    If there's no value to display, default to a "waiting" message.
    """
    w = Window('mock')
    w.main_view = mocker.MagicMock()
    w.show_sync(None)
    w.main_view.status.setText.assert_called_once_with('Waiting to refresh...')
コード例 #6
0
def test_show_sync_no_sync():
    """
    If there's no value to display, default to a "waiting" message.
    """
    w = Window()
    w.main_view = mock.MagicMock()
    w.show_sync(None)
    w.main_view.status.setText.\
        assert_called_once_with('Waiting to Synchronize')
コード例 #7
0
def test_conversation_for(mocker):
    """
    Test that the source collection is displayed in the conversation view.
    """
    w = Window('mock')
    w.controller = mocker.MagicMock()
    w.main_view = mocker.MagicMock()
    mock_source = mocker.MagicMock()
    mock_source.journalistic_designation = 'Testy McTestface'
    mock_file = mocker.MagicMock()
    mock_file.filename = '1-my-source-doc.gpg'
    mock_message = mocker.MagicMock()
    mock_message.filename = '2-my-source-msg.gpg'
    mock_reply = mocker.MagicMock()
    mock_reply.filename = '3-my-source-reply.gpg'
    mock_source.collection = [mock_file, mock_message, mock_reply]

    mocked_add_message = mocker.patch(
        'securedrop_client.gui.widgets.ConversationView.add_message',
        new=mocker.Mock())
    mocked_add_reply = mocker.patch(
        'securedrop_client.gui.widgets.ConversationView.add_reply',
        new=mocker.Mock())
    mocked_add_file = mocker.patch(
        'securedrop_client.gui.widgets.ConversationView.add_file',
        new=mocker.Mock())

    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

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

    # stop the old mockers
    mocked_add_message.stop()
    mocked_add_reply.stop()
    mocked_add_file.stop()

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

    w.show_conversation_for(mock_source)

    # because the conversation was cached, we don't call these functions again
    assert mocked_add_message.call_count == 0
    assert mocked_add_reply.call_count == 0
    assert mocked_add_file.call_count == 0
コード例 #8
0
def test_show_sync():
    """
    If there's a value display the result of its "humanize" method.
    """
    w = Window()
    w.main_view = mock.MagicMock()
    updated_on = mock.MagicMock()
    w.show_sync(updated_on)
    w.main_view.status.setText.assert_called_once_with('Last Sync: ' +
                                                       updated_on.humanize())
コード例 #9
0
def test_update_error_status():
    """
    Ensure that the error to be shown in the error status sidebar will
    be passed to the left sidebar for display.
    """
    error_message = "this is a bad thing!"
    w = Window()
    w.main_view = mock.MagicMock()
    w.update_error_status(error=error_message)
    w.main_view.update_error_status.assert_called_once_with(error_message)
コード例 #10
0
def test_refresh_current_source_conversation(mocker):
    """
    Ensure on_source_changed is called on the MainView (which
    updates the current conversation) when
    refresh_current_source_conversation() is called.
    """
    w = Window()
    w.main_view = mocker.MagicMock()

    w.refresh_current_source_conversation()

    w.main_view.on_source_changed.assert_called_once_with()
コード例 #11
0
def test_on_source_changed():
    """
    Ensure the event handler for when a source is changed calls the
    show_conversation_for method with the expected source object.
    """
    w = Window()
    w.main_view = mock.MagicMock()
    mock_si = w.main_view.source_list.currentItem()
    mock_sw = w.main_view.source_list.itemWidget()
    w.show_conversation_for = mock.MagicMock()
    w.on_source_changed()
    w.show_conversation_for.assert_called_once_with(mock_sw.source)
コード例 #12
0
def test_conversation_for():
    """
    TODO: Finish this once we have data. Currently checks only the GUI layer
    is called in the expected manner with dummy data.
    """
    w = Window()
    w.main_view = mock.MagicMock()
    mock_conview = mock.MagicMock()
    mock_source = mock.MagicMock()
    mock_source.journalistic_designation = 'Testy McTestface'
    with mock.patch('securedrop_client.gui.main.ConversationView',
                    mock_conview):
        w.show_conversation_for(mock_source)
    conv = mock_conview()
    assert conv.add_message.call_count > 0
    assert conv.add_reply.call_count > 0
コード例 #13
0
def test_setup(mocker):
    """
    Ensure the passed in controller is referenced and the various views are
    instantiated as expected.
    """
    w = Window()
    mock_controller = mocker.MagicMock()
    w.show_login = mocker.MagicMock()
    w.top_pane = mocker.MagicMock()
    w.left_pane = mocker.MagicMock()
    w.main_view = mocker.MagicMock()

    w.setup(mock_controller)

    assert w.controller == mock_controller
    w.top_pane.setup.assert_called_once_with(mock_controller)
    w.left_pane.setup.assert_called_once_with(w, mock_controller)
    w.main_view.setup.assert_called_once_with(mock_controller)
    w.show_login.assert_called_once_with()
コード例 #14
0
def test_conversation_for():
    """
    Test that the source collection is displayed in the conversation view.
    """
    w = Window()
    w.controller = mock.MagicMock()
    w.main_view = mock.MagicMock()
    mock_conview = mock.MagicMock()
    mock_source = mock.MagicMock()
    mock_source.journalistic_designation = 'Testy McTestface'
    mock_file = mock.MagicMock()
    mock_file.filename = '1-my-source-doc.gpg'
    mock_message = mock.MagicMock()
    mock_message.filename = '2-my-source-msg.gpg'
    mock_reply = mock.MagicMock()
    mock_reply.filename = '3-my-source-reply.gpg'
    mock_source.collection = [mock_file, mock_message, mock_reply]
    with mock.patch('securedrop_client.gui.main.ConversationView',
                    mock_conview):
        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