Beispiel #1
0
def test_SourceWidget_delete_source_when_user_chooses_cancel(mocker):
    mock_message_box_question = mocker.MagicMock(QMessageBox.question)
    mock_message_box_question.return_value = QMessageBox.Cancel

    mock_source = mocker.MagicMock()
    mock_source.journalist_designation = 'foo bar baz'
    mock_source.submissions = []

    submission_files = (
        "submission_1-msg.gpg",
        "submission_2-msg.gpg",
        "submission_3-doc.gpg",
    )
    for filename in submission_files:
        submission = mocker.MagicMock()
        submission.filename = filename
        mock_source.submissions.append(submission)

    mock_controller = mocker.MagicMock()
    sw = SourceWidget(None, mock_source)
    sw.controller = mock_controller

    mocker.patch(
        "securedrop_client.gui.widgets.QMessageBox.question",
        mock_message_box_question,
    )
    sw.delete_source(None)
    sw.controller.delete_source.assert_not_called()
def test_SourceWidget_setup():
    """
    The setup method adds the controller as an attribute on the SourceWidget.
    """
    mock_controller = mock.MagicMock()
    mock_source = mock.MagicMock()
    sw = SourceWidget(None, mock_source)
    sw.setup(mock_controller)
    assert sw.controller == mock_controller
def test_SourceWidget_toggle_star():
    """
    The toggle_star method should call self.controller.update_star
    """
    mock_controller = mock.MagicMock()
    mock_source = mock.MagicMock()
    event = mock.MagicMock()
    sw = SourceWidget(None, mock_source)
    sw.controller = mock_controller
    sw.controller.update_star = mock.MagicMock()
    sw.toggle_star(event)
    sw.controller.update_star.assert_called_once_with(mock_source)
Beispiel #4
0
def test_SourceWidget_update_unstarred():
    """
    Ensure the widget displays the expected details from the source.
    """
    mock_source = mock.MagicMock()
    mock_source.journalist_designation = 'foo bar baz'
    mock_source.is_starred = False
    sw = SourceWidget(None, mock_source)
    sw.name = mock.MagicMock()
    with mock.patch('securedrop_client.gui.widgets.load_svg') as mock_load:
        sw.update()
        mock_load.assert_called_once_with('star_off.svg')
    sw.name.setText.assert_called_once_with('<strong>foo bar baz</strong>')
def test_SourceWidget_init():
    """
    The source widget is initialised with the passed-in source.
    """
    mock_source = mock.MagicMock()
    mock_source.journalist_designation = 'foo bar baz'
    sw = SourceWidget(None, mock_source)
    assert sw.source == mock_source
Beispiel #6
0
def test_SourceWidget_delete_source(mocker):
    mock_source = mocker.MagicMock()
    mock_delete_source_message_box_object = mocker.MagicMock(
        DeleteSourceMessageBox)
    mock_controller = mocker.MagicMock()
    mock_delete_source_message = mocker.MagicMock(
        return_value=mock_delete_source_message_box_object)

    sw = SourceWidget(None, mock_source)
    sw.controller = mock_controller

    mocker.patch(
        "securedrop_client.gui.widgets.DeleteSourceMessageBox",
        mock_delete_source_message,
    )

    sw.delete_source(None)
    mock_delete_source_message_box_object.launch.assert_called_with()
Beispiel #7
0
def test_SourceWidget_update_attachment_icon():
    """
    Attachment icon identicates document count
    """
    source = factory.Source(document_count=1)
    sw = SourceWidget(None, source)

    sw.update()
    assert not sw.attached.isHidden()

    source.document_count = 0

    sw.update()
    assert sw.attached.isHidden()
Beispiel #8
0
def test_DeleteSource_from_source_widget_when_user_is_loggedout(mocker):
    mock_source = mocker.MagicMock()
    mock_controller = mocker.MagicMock(logic.Client)
    mock_controller.api = None
    mock_event = mocker.MagicMock()
    mock_delete_source_message_box_obj = mocker.MagicMock()
    mock_delete_source_message_box = mocker.MagicMock()
    mock_delete_source_message_box.return_value = (
        mock_delete_source_message_box_obj)

    with mocker.patch('securedrop_client.gui.widgets.DeleteSourceMessageBox',
                      mock_delete_source_message_box):
        source_widget = SourceWidget(None, mock_source)
        source_widget.setup(mock_controller)
        source_widget.delete_source(mock_event)
        mock_delete_source_message_box_obj.launch.assert_not_called()
Beispiel #9
0
def test_SourceWidget_html_init(mocker):
    """
    The source widget is initialised with the given source name, with
    HTML escaped properly.
    """
    mock_source = mocker.MagicMock()
    mock_source.journalist_designation = 'foo <b>bar</b> baz'

    sw = SourceWidget(None, mock_source)
    sw.name = mocker.MagicMock()
    sw.summary_layout = mocker.MagicMock()

    mocker.patch('securedrop_client.gui.widgets.load_svg')
    sw.update()

    sw.name.setText.assert_called_once_with(
        '<strong>foo &lt;b&gt;bar&lt;/b&gt; baz</strong>')