Exemplo n.º 1
0
def test_get_version_error(qtbot):
    """Test get_version() when error is emitted."""
    http_stub = HTTPGetStub(success=False)
    client = autoupdate.PyPIVersionClient(client=http_stub)

    with qtbot.assertNotEmitted(client.success):
        with qtbot.waitSignal(client.error):
            client.get_version('test')
Exemplo n.º 2
0
    def __init__(self, debug, parent=None):
        """Constructor for CrashDialog.

        Args:
            debug: Whether --debug was given.
        """
        super().__init__(parent)
        # We don't set WA_DeleteOnClose here as on an exception, we'll get
        # closed anyways, and it only could have unintended side-effects.
        self._crash_info = []  # type: typing.Sequence[typing.Tuple[str, str]]
        self._btn_box = None
        self._btn_report = None
        self._btn_cancel = None
        self._lbl = None
        self._paste_text = None
        self.setWindowTitle("Whoops!")
        self.resize(QSize(640, 600))
        self._vbox = QVBoxLayout(self)
        http_client = httpclient.HTTPClient()
        self._paste_client = pastebin.PastebinClient(http_client, self)
        self._pypi_client = autoupdate.PyPIVersionClient(self)
        self._init_text()

        self._init_contact_input()

        info = QLabel("What were you doing when this crash/bug happened?")
        self._vbox.addWidget(info)
        self._info = QTextEdit()
        self._info.setTabChangesFocus(True)
        self._info.setAcceptRichText(False)
        self._info.setPlaceholderText("- Opened http://www.example.com/\n"
                                      "- Switched tabs\n"
                                      "- etc...")
        self._vbox.addWidget(self._info, 5)

        self._vbox.addSpacing(15)
        self._debug_log = QTextEdit()
        self._debug_log.setTabChangesFocus(True)
        self._debug_log.setAcceptRichText(False)
        self._debug_log.setLineWrapMode(QTextEdit.NoWrap)
        self._debug_log.hide()
        info = QLabel("<i>You can edit the log below to remove sensitive "
                      "information.</i>")
        info.setWordWrap(True)
        info.hide()
        self._fold = miscwidgets.DetailFold("Show log", self)
        self._fold.toggled.connect(self._debug_log.setVisible)
        self._fold.toggled.connect(info.setVisible)
        if debug:
            self._fold.toggle()
        self._vbox.addWidget(self._fold)
        self._vbox.addWidget(info)
        self._vbox.addWidget(self._debug_log, 10)
        self._vbox.addSpacing(15)

        self._init_checkboxes()
        self._init_info_text()
        self._init_buttons()
Exemplo n.º 3
0
def test_invalid_json(qtbot, json):
    """Test on_client_success() with invalid JSON."""
    http_stub = HTTPGetStub(json=json)
    client = autoupdate.PyPIVersionClient(client=http_stub)
    client.get_version('test')

    with qtbot.assertNotEmitted(client.success):
        with qtbot.waitSignal(client.error):
            client.get_version('test')
Exemplo n.º 4
0
def test_get_version_success(qtbot):
    """Test get_version() when success is emitted."""
    http_stub = HTTPGetStub(success=True)
    client = autoupdate.PyPIVersionClient(client=http_stub)

    with qtbot.assertNotEmitted(client.error):
        with qtbot.waitSignal(client.success):
            client.get_version('test')

    assert http_stub.url == QUrl(client.API_URL.format('test'))
Exemplo n.º 5
0
def test_get_version_success(qtbot):
    """Test get_version() when success is emitted."""
    http_stub = HTTPGetStub(success=True)
    client = autoupdate.PyPIVersionClient(client=http_stub)

    with qtbot.assertNotEmitted(client.error):
        with qtbot.waitSignal(client.success):
            client.get_version('test')

    assert http_stub.url == QUrl('https://pypi.python.org/pypi/test/json')
Exemplo n.º 6
0
def test_get_version_error(qtbot):
    """Test get_version() when error is emitted."""
    http_stub = HTTPGetStub(success=False)
    client = autoupdate.PyPIVersionClient(client=http_stub)

    # Use a spy to inspect the signal
    success_spy = QSignalSpy(client.success)

    with qtbot.waitSignal(client.error, raising=True):
        client.get_version('test')

    assert len(success_spy) == 0
Exemplo n.º 7
0
def test_invalid_json(qtbot, json):
    """Test on_client_success() with invalid JSON."""
    http_stub = HTTPGetStub(json=json)
    client = autoupdate.PyPIVersionClient(client=http_stub)
    client.get_version('test')

    # Use a spy to inspect the signal
    success_spy = QSignalSpy(client.success)

    with qtbot.waitSignal(client.error, raising=True):
        client.get_version('test')

    assert len(success_spy) == 0
Exemplo n.º 8
0
def test_get_version_success(qtbot):
    """Test get_version() when success is emitted."""
    http_stub = HTTPGetStub(success=True)
    client = autoupdate.PyPIVersionClient(client=http_stub)

    # Use a spy to inspect the signal
    error_spy = QSignalSpy(client.error)

    with qtbot.waitSignal(client.success, raising=True):
        client.get_version('test')

    assert len(error_spy) == 0

    assert http_stub.url == QUrl('https://pypi.python.org/pypi/test/json')
Exemplo n.º 9
0
def test_constructor(qapp):
    client = autoupdate.PyPIVersionClient()
    assert isinstance(client._client, httpclient.HTTPClient)
Exemplo n.º 10
0
    def __init__(self, debug, parent=None):
        """Constructor for CrashDialog.

        Args:
            debug: Whether --debug was given.
        """
        super().__init__(parent)
        # We don't set WA_DeleteOnClose here as on an exception, we'll get
        # closed anyways, and it only could have unintended side-effects.
        self._crash_info = []
        self._btn_box = None
        self._btn_report = None
        self._btn_cancel = None
        self._lbl = None
        self._paste_text = None
        self.setWindowTitle("Whoops!")
        self.resize(QSize(640, 600))
        self._vbox = QVBoxLayout(self)
        http_client = httpclient.HTTPClient()
        self._paste_client = pastebin.PastebinClient(http_client, self)
        self._pypi_client = autoupdate.PyPIVersionClient(self)
        self._init_text()

        contact = QLabel(
            "I'd like to be able to follow up with you, to keep "
            "you posted on the status of this crash and get more "
            "information if I need it - how can I contact you?",
            wordWrap=True)
        self._vbox.addWidget(contact)
        self._contact = QTextEdit(tabChangesFocus=True, acceptRichText=False)
        try:
            state = objreg.get('state-config')
            try:
                self._contact.setPlainText(state['general']['contact-info'])
            except KeyError:
                self._contact.setPlaceholderText("Mail or IRC nickname")
        except Exception:
            log.misc.exception("Failed to get contact information!")
            self._contact.setPlaceholderText("Mail or IRC nickname")
        self._vbox.addWidget(self._contact, 2)

        info = QLabel("What were you doing when this crash/bug happened?")
        self._vbox.addWidget(info)
        self._info = QTextEdit(tabChangesFocus=True, acceptRichText=False)
        self._info.setPlaceholderText("- Opened http://www.example.com/\n"
                                      "- Switched tabs\n"
                                      "- etc...")
        self._vbox.addWidget(self._info, 5)

        self._vbox.addSpacing(15)
        self._debug_log = QTextEdit(tabChangesFocus=True,
                                    acceptRichText=False,
                                    lineWrapMode=QTextEdit.NoWrap)
        self._debug_log.hide()
        info = QLabel(
            "<i>You can edit the log below to remove sensitive "
            "information.</i>",
            wordWrap=True)
        info.hide()
        self._fold = miscwidgets.DetailFold("Show log", self)
        self._fold.toggled.connect(self._debug_log.setVisible)
        self._fold.toggled.connect(info.setVisible)
        if debug:
            self._fold.toggle()
        self._vbox.addWidget(self._fold)
        self._vbox.addWidget(info)
        self._vbox.addWidget(self._debug_log, 10)
        self._vbox.addSpacing(15)

        self._init_checkboxes()
        self._init_info_text()
        self._init_buttons()