Skip to content
Permalink
Browse files
adds finished signal and deprecates downloadFinished
  • Loading branch information
troopa81 committed Aug 24, 2021
1 parent 385939c commit ff08ad47337aae08135dc33c9d6bffabeadd56ff
@@ -207,16 +207,24 @@ Aborts the network request immediately.
Emitted when when data arrives during a request.
%End

void downloadFinished();
void downloadFinished() /Deprecated/;
%Docstring
Emitted once a request has finished downloading.

.. deprecated::
Use the :py:func:`~QgsBlockingNetworkRequest.finished` signal instead.
%End

void uploadProgress( qint64, qint64 );
%Docstring
Emitted when when data are sent during a request.

.. versionadded:: 3.22
%End

void finished();
%Docstring
Emitted once a request has finished.
%End

};
@@ -221,7 +221,7 @@ QgsBlockingNetworkRequest::ErrorCode QgsBlockingNetworkRequest::doRequest( QgsBl
// when QThreadPool::globalInstance()->waitForDone()
// is called at process termination
connect( qApp, &QCoreApplication::aboutToQuit, &loop, &QEventLoop::quit, Qt::DirectConnection );
connect( this, &QgsBlockingNetworkRequest::downloadFinished, &loop, &QEventLoop::quit, Qt::DirectConnection );
connect( this, &QgsBlockingNetworkRequest::finished, &loop, &QEventLoop::quit, Qt::DirectConnection );
loop.exec();
}

@@ -343,7 +343,10 @@ void QgsBlockingNetworkRequest::replyFinished()
mErrorMessage = errorMessageFailedAuth();
mErrorCode = NetworkError;
QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
emit finished();
Q_NOWARN_DEPRECATED_PUSH
emit downloadFinished();
Q_NOWARN_DEPRECATED_POP
return;
}

@@ -366,7 +369,10 @@ void QgsBlockingNetworkRequest::replyFinished()
mErrorMessage = errorMessageFailedAuth();
mErrorCode = NetworkError;
QgsMessageLog::logMessage( mErrorMessage, tr( "Network" ) );
emit finished();
Q_NOWARN_DEPRECATED_PUSH
emit downloadFinished();
Q_NOWARN_DEPRECATED_POP
return;
}

@@ -443,7 +449,10 @@ void QgsBlockingNetworkRequest::replyFinished()
mReply = nullptr;
}

emit finished();
Q_NOWARN_DEPRECATED_PUSH
emit downloadFinished();
Q_NOWARN_DEPRECATED_POP
}

QString QgsBlockingNetworkRequest::errorMessageFailedAuth()
@@ -220,15 +220,21 @@ class CORE_EXPORT QgsBlockingNetworkRequest : public QObject

/**
* Emitted once a request has finished downloading.
* \deprecated Use the finished() signal instead.
*/
void downloadFinished();
Q_DECL_DEPRECATED void downloadFinished() SIP_DEPRECATED;

/**
* Emitted when when data are sent during a request.
* \since QGIS 3.22
*/
void uploadProgress( qint64, qint64 );

/**
* Emitted once a request has finished.
*/
void finished();

private slots:
void replyProgress( qint64, qint64 );
void replyFinished();
@@ -39,7 +39,7 @@ def tearDownClass(cls):

def testFetchEmptyUrl(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
err = request.get(QNetworkRequest(QUrl()))
self.assertEqual(len(spy), 1)
self.assertEqual(err, QgsBlockingNetworkRequest.ServerExceptionError)
@@ -49,7 +49,7 @@ def testFetchEmptyUrl(self):

def testFetchBadUrl(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
err = request.get(QNetworkRequest(QUrl('http://x')))
self.assertEqual(len(spy), 1)
self.assertEqual(err, QgsBlockingNetworkRequest.ServerExceptionError)
@@ -59,7 +59,7 @@ def testFetchBadUrl(self):

def testFetchBadUrl2(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)

handler = mockedwebserver.SequentialHandler()
handler.add('GET', '/ffff', 404, {}, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n "http://www.w3.org/TR/html4/strict.dtd">\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html;charset=utf-8">\n <title>Error response</title>\n </head>\n <body>\n <h1>Error response</h1>\n <p>Error code: 404</p>\n <p>Message: File not found.</p>\n <p>Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.</p>\n </body>\n</html>\n')
@@ -74,7 +74,7 @@ def testFetchBadUrl2(self):

def testGet(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
handler = mockedwebserver.SequentialHandler()
handler.add('GET', '/test.html', 200, {'Content-type': 'text/html'}, '<html></html>\n')
with mockedwebserver.install_http_handler(handler):
@@ -97,7 +97,7 @@ def testGet(self):

def testHead(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
handler = mockedwebserver.SequentialHandler()
handler.add('HEAD', '/test.html', 200, {'Content-type': 'text/html'})
with mockedwebserver.install_http_handler(handler):
@@ -108,7 +108,7 @@ def testHead(self):

def testPost(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
handler = mockedwebserver.SequentialHandler()
handler.add('POST', '/test.html', 200, expected_body=b"foo")
with mockedwebserver.install_http_handler(handler):
@@ -120,19 +120,20 @@ def testPost(self):

def testPut(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
handler = mockedwebserver.SequentialHandler()
handler.add('PUT', '/test.html', 200, expected_body=b"foo")
with mockedwebserver.install_http_handler(handler):
req = QNetworkRequest(QUrl('http://localhost:' + str(TestQgsBlockingNetworkRequest.port) + '/test.html'))
req.setHeader(QNetworkRequest.ContentTypeHeader, 'text/plain')
err = request.put(req, b"foo")
self.assertEqual(len(spy), 1)
self.assertEqual(err, QgsBlockingNetworkRequest.NoError)
self.assertEqual(request.errorMessage(), '')

def testDelete(self):
request = QgsBlockingNetworkRequest()
spy = QSignalSpy(request.downloadFinished)
spy = QSignalSpy(request.finished)
handler = mockedwebserver.SequentialHandler()
handler.add('DELETE', '/test.html', 200)
with mockedwebserver.install_http_handler(handler):

0 comments on commit ff08ad4

Please sign in to comment.