コード例 #1
0
ファイル: test_export.py プロジェクト: sjhgithub/mitmproxy-1
async def test_clip(tmpdir):
    e = export.Export()
    with taddons.context() as tctx:
        with pytest.raises(exceptions.CommandError):
            e.clip("nonexistent", tflow.tflow(resp=True))

        with mock.patch('pyperclip.copy') as pc:
            e.clip("raw_request", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            e.clip("raw_response", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            e.clip("curl", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            e.clip("httpie", tflow.tflow(resp=True))
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            log_message = "Pyperclip could not find a " \
                          "copy/paste mechanism for your system."
            pc.side_effect = pyperclip.PyperclipException(log_message)
            e.clip("raw_request", tflow.tflow(resp=True))
            assert await tctx.master.await_log(log_message, level="error")
コード例 #2
0
ファイル: test_cut.py プロジェクト: ronakodhaviya/project-X
def test_cut_clip():
    v = view.View()
    c = cut.Cut()
    with taddons.context() as tctx:
        tctx.master.addons.add(v, c)
        v.add([tflow.tflow(resp=True)])

        with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.method")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.content")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            tctx.command(c.clip, "@all", "request.method,request.content")
            assert pc.called

        with mock.patch('pyperclip.copy') as pc:
            log_message = "Pyperclip could not find a " \
                          "copy/paste mechanism for your system."
            pc.side_effect = pyperclip.PyperclipException(log_message)
            tctx.command(c.clip, "@all", "request.method")
            assert tctx.master.has_log(log_message, level="error")
コード例 #3
0
def _get_source_code(code, code_file):
    if code is not None:
        return code
    if code_file is not None:
        with open(code_file) as fi:
            return fi.read()
    try:
        return pyperclip.paste()
    except pyperclip.PyperclipException:
        raise pyperclip.PyperclipException(
            'Could not retrieve code from the clipboard. '
            'Try putting your code in a file and using '
            'the `code_file` parameter instead of using the clipboard.')
コード例 #4
0
    def test_copy_to_clipboard_exception(
        self, mocker: MockerFixture, controller: Controller, text_category: str = "Test"
    ) -> None:
        popup = mocker.patch(MODULE + ".Controller.show_pop_up")
        mocker.patch(
            MODULE + ".pyperclip.copy", side_effect=pyperclip.PyperclipException()
        )
        mocker.patch(
            MODULE + ".Controller.maximum_popup_dimensions", return_value=(64, 64)
        )

        controller.copy_to_clipboard("copy text", text_category)

        popup.assert_called_once()
        assert popup.call_args_list[0][0][1] == "area:error"