Skip to content

Commit c03ce93

Browse files
committed
Allow use of local httpbin instances in unit tests
1 parent f1040ef commit c03ce93

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/src/core/testqgsnetworkaccessmanager.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class TestQgsNetworkAccessManager : public QObject
116116
void testAuthRequestHandler();
117117
void fetchTimeout();
118118

119+
private:
120+
121+
QString mHttpBinHost;
122+
119123
};
120124

121125
void TestQgsNetworkAccessManager::initTestCase()
@@ -129,6 +133,11 @@ void TestQgsNetworkAccessManager::initTestCase()
129133
QgsApplication::initQgis();
130134

131135
QgsSettings().setValue( QStringLiteral( "/qgis/networkAndProxy/networkTimeout" ), 1000 );
136+
137+
mHttpBinHost = QStringLiteral( "httpbin.org" );
138+
QString overrideHost = qgetenv( "QGIS_HTTPBIN_HOST" );
139+
if ( !overrideHost.isEmpty() )
140+
mHttpBinHost = overrideHost;
132141
}
133142

134143
void TestQgsNetworkAccessManager::cleanupTestCase()
@@ -320,7 +329,7 @@ void TestQgsNetworkAccessManager::fetchPost()
320329
bool loaded = false;
321330
bool gotRequestAboutToBeCreatedSignal = false;
322331
int requestId = -1;
323-
QUrl u = QUrl( QStringLiteral( "http://httpbin.org/post" ) );
332+
QUrl u = QUrl( QStringLiteral( "http://" ) + mHttpBinHost + QStringLiteral( "/post" ) );
324333
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
325334
{
326335
gotRequestAboutToBeCreatedSignal = true;
@@ -525,7 +534,7 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
525534
QString expectedUser;
526535
QString expectedPassword;
527536
int requestId = -1;
528-
QUrl u = QUrl( QStringLiteral( "http://httpbin.org/basic-auth/me/secret" ) );
537+
QUrl u = QUrl( QStringLiteral( "http://" ) + mHttpBinHost + QStringLiteral( "/basic-auth/me/secret" ) );
529538
QNetworkReply::NetworkError expectedError = QNetworkReply::NoError;
530539
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
531540
{
@@ -606,7 +615,7 @@ void TestQgsNetworkAccessManager::testAuthRequestHandler()
606615

607616
// correct username and password, in a thread
608617
QgsNetworkAccessManager::instance()->setAuthHandler( qgis::make_unique< TestAuthRequestHandler >( QStringLiteral( "me2" ), QStringLiteral( "secret2" ) ) );
609-
u = QUrl( QStringLiteral( "http://httpbin.org/basic-auth/me2/secret2" ) );
618+
u = QUrl( QStringLiteral( "http://" ) + mHttpBinHost + QStringLiteral( "/basic-auth/me2/secret2" ) );
610619
loaded = false;
611620
gotAuthRequest = false;
612621
gotRequestAboutToBeCreatedSignal = false;
@@ -644,7 +653,7 @@ void TestQgsNetworkAccessManager::fetchTimeout()
644653
bool gotTimeoutError = false;
645654
bool finished = false;
646655
int requestId = -1;
647-
QUrl u = QUrl( QStringLiteral( "http://httpbin.org/delay/10" ) );
656+
QUrl u = QUrl( QStringLiteral( "http://" ) + mHttpBinHost + QStringLiteral( "/delay/10" ) );
648657
connect( QgsNetworkAccessManager::instance(), qgis::overload< QgsNetworkRequestParameters >::of( &QgsNetworkAccessManager::requestAboutToBeCreated ), &context, [&]( const QgsNetworkRequestParameters & params )
649658
{
650659
gotRequestAboutToBeCreatedSignal = true;

0 commit comments

Comments
 (0)