コード例 #1
0
def test_Client_on_file_download_Reply(safe_tmpdir):
    """
    If the handler is passed a reply, check the download_reply
    function is the one called against the API.
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    source = models.Source('source-uuid', 'testy-mctestface', False,
                           'mah pub key', 1, False, datetime.now())
    journalist = models.User('Testy mcTestface')
    reply = models.Reply('reply-uuid', journalist, source, 'my-reply.gpg',
                         123)  # Not a sdclientapi.Submission
    cl.call_api = mock.MagicMock()
    cl.api = mock.MagicMock()
    reply_sdk_object = mock.MagicMock()
    with mock.patch('sdclientapi.Reply') as mock_reply:
        mock_reply.return_value = reply_sdk_object
        cl.on_file_download(source, reply)
    cl.call_api.assert_called_once_with(cl.api.download_reply,
                                        cl.on_file_downloaded,
                                        cl.on_download_timeout,
                                        reply_sdk_object,
                                        cl.data_dir,
                                        current_object=reply)
コード例 #2
0
def test_FileWidget_mousePressEvent_open():
    """
    Should fire the expected open event handler in the logic layer.
    """
    mock_controller = mock.MagicMock()
    source = models.Source('source-uuid', 'testy-mctestface', False,
                           'mah pub key', 1, False, datetime.now())
    submission = models.Submission(source, 'submission-uuid', 123,
                                   'mah-reply.gpg',
                                   'http://mah-server/mah-reply-url')
    submission.is_downloaded = True

    fw = FileWidget(source, submission, mock_controller)
    fw.mouseReleaseEvent(None)
    fw.controller.on_file_open.assert_called_once_with(submission)
コード例 #3
0
def test_FileWidget_init_right():
    """
    Check the FileWidget is configured correctly for align-right.
    """
    mock_controller = mock.MagicMock()
    source = models.Source('source-uuid', 'testy-mctestface', False,
                           'mah pub key', 1, False, datetime.now())
    submission = models.Submission(source, 'submission-uuid', 123,
                                   'mah-reply.gpg',
                                   'http://mah-server/mah-reply-url')
    submission.is_downloaded = True

    fw = FileWidget(source, submission, mock_controller, align='right')
    layout = fw.layout()
    assert isinstance(layout.takeAt(0), QSpacerItem)
    assert isinstance(layout.takeAt(0), QWidgetItem)
    assert isinstance(layout.takeAt(0), QWidgetItem)
    assert fw.controller == mock_controller
コード例 #4
0
def test_Client_on_file_download_Submission(safe_tmpdir):
    """
    If the handler is passed a submission, check the download_submission
    function is the one called against the API.
    """
    mock_gui = mock.MagicMock()
    mock_session = mock.MagicMock()
    cl = Client('http://localhost', mock_gui, mock_session, str(safe_tmpdir))
    source = models.Source('source-uuid', 'testy-mctestface', False,
                           'mah pub key', 1, False, datetime.now())
    submission = models.Submission(source, 'submission-uuid', 1234,
                                   'myfile.doc.gpg', 'http://myserver/myfile')
    cl.call_api = mock.MagicMock()
    cl.api = mock.MagicMock()
    submission_sdk_object = mock.MagicMock()
    with mock.patch('sdclientapi.Submission') as mock_submission:
        mock_submission.return_value = submission_sdk_object
        cl.on_file_download(source, submission)
    cl.call_api.assert_called_once_with(cl.api.download_submission,
                                        cl.on_file_downloaded,
                                        cl.on_download_timeout,
                                        submission_sdk_object,
                                        cl.data_dir,
                                        current_object=submission)