def test_getTimeout() -> None:
    time.sleep(0.5)
    app = QCoreApplication([])
    http_request_manager = HttpRequestManager.getInstance()

    cbo = mock.Mock()

    def error_callback(*args, **kwargs):
        cbo.error_callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    request_data = http_request_manager.get(
        url="http://localhost:8080/timeout",
        error_callback=error_callback,
        timeout=4)
    # Make sure that if something goes wrong, we quit after 10 seconds
    http_request_manager.callLater(10.0, app.quit)

    app.exec()
    http_request_manager.cleanup()  # Remove all unscheduled events

    cbo.error_callback.assert_called_once_with(
        request_data.reply, QNetworkReply.OperationCanceledError)
    assert request_data.is_aborted_due_to_timeout
def test_getFail404() -> None:
    time.sleep(0.5)
    app = QCoreApplication([])
    http_request_manager = HttpRequestManager.getInstance()

    cbo = mock.Mock()

    def callback(*args, **kwargs):
        cbo.callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    def error_callback(*args, **kwargs):
        cbo.error_callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    request_data = http_request_manager.get(
        url="http://localhost:8080/do_not_exist",
        callback=callback,
        error_callback=error_callback)
    # Make sure that if something goes wrong, we quit after 10 seconds
    http_request_manager.callLater(10.0, app.quit)

    app.exec()
    http_request_manager.cleanup()  # Remove all unscheduled events

    cbo.error_callback.assert_called_once_with(
        request_data.reply, QNetworkReply.ContentNotFoundError)
    cbo.callback.assert_not_called()
def test_getBasicAuthSuccess() -> None:
    time.sleep(0.5)
    app = QCoreApplication([])
    http_request_manager = HttpRequestManager.getInstance()

    cbo = mock.Mock()

    def callback(*args, **kwargs):
        cbo.callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    def error_callback(*args, **kwargs):
        cbo.callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    request_data = http_request_manager.get(
        url="http://localhost:8080/auth",
        headers_dict={"Authorization": "Basic dXNlcjp1c2Vy"},
        callback=callback,
        error_callback=error_callback)
    # Make sure that if something goes wrong, we quit after 10 seconds
    http_request_manager.callLater(10.0, app.quit)

    app.exec()
    http_request_manager.cleanup()  # Remove all unscheduled events

    cbo.callback.assert_called_once_with(request_data.reply)
    cbo.error_callback.assert_not_called()
Exemple #4
0
    def __init__(self, gui_enabled=True):
        # Start Qt
        if EventLoop.qt is None:
            EventLoop.qt = QCoreApplication.instance() or QApplication(
                []) if gui_enabled else QCoreApplication([])

        asyncframes.AbstractEventLoop.__init__(self)
        QObject.__init__(self)
        self.moveToThread(QThread.currentThread())
def test_getSuccessful() -> None:
    app = QCoreApplication([])
    http_request_manager = HttpRequestManager.getInstance()

    cbo = mock.Mock()

    def callback(*args, **kwargs):
        cbo.callback(*args, **kwargs)
        # quit now so we don't need to wait
        http_request_manager.callLater(0, app.quit)

    request_data = http_request_manager.get(url = "http://localhost:8080/success", callback = callback)
    # Make sure that if something goes wrong, we quit after 10 seconds
    http_request_manager.callLater(10.0, app.quit)

    app.exec()
    http_request_manager.cleanup()  # Remove all unscheduled events

    cbo.callback.assert_called_once_with(request_data.reply)
Exemple #6
0
def main():
    app = QCoreApplication(sys.argv)
    x = HKUImportDataCMD()
    x.start_import_data()
    sys.exit(app.exec())