Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start implementing the provider test suite for ArcGIS Feature Server …
…provider
  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent 227689a commit b434ab1
Show file tree
Hide file tree
Showing 4 changed files with 497 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/providers/arcgisrest/qgsarcgisrestutils.cpp
Expand Up @@ -415,9 +415,10 @@ QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QList
return queryServiceJSON( queryUrl, errorTitle, errorText );
}

QByteArray QgsArcGisRestUtils::queryService( const QUrl &url, QString &errorTitle, QString &errorText )
QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, QString &errorTitle, QString &errorText )
{
QEventLoop loop;
QUrl url = parseUrl( u );

QNetworkRequest request( url );
QNetworkReply *reply = nullptr;
Expand Down Expand Up @@ -477,6 +478,52 @@ QVariantMap QgsArcGisRestUtils::queryServiceJSON( const QUrl &url, QString &erro
return doc.object().toVariantMap();
}

QUrl QgsArcGisRestUtils::parseUrl( const QUrl &url )
{
QUrl modifiedUrl( url );
if ( modifiedUrl.toString().contains( QLatin1String( "fake_qgis_http_endpoint" ) ) )
{
// Just for testing with local files instead of http:// resources
QString modifiedUrlString = modifiedUrl.toString();
// Qt5 does URL encoding from some reason (of the FILTER parameter for example)
modifiedUrlString = QUrl::fromPercentEncoding( modifiedUrlString.toUtf8() );
modifiedUrlString.replace( QStringLiteral( "fake_qgis_http_endpoint/" ), QStringLiteral( "fake_qgis_http_endpoint_" ) );
QgsDebugMsg( QString( "Get %1" ).arg( modifiedUrlString ) );
modifiedUrlString = modifiedUrlString.mid( QStringLiteral( "http://" ).size() );
QString args = modifiedUrlString.mid( modifiedUrlString.indexOf( '?' ) );
if ( modifiedUrlString.size() > 256 )
{
args = QCryptographicHash::hash( args.toUtf8(), QCryptographicHash::Md5 ).toHex();
}
else
{
args.replace( QLatin1String( "?" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "&" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "<" ), QLatin1String( "_" ) );
args.replace( QLatin1String( ">" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "'" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "\"" ), QLatin1String( "_" ) );
args.replace( QLatin1String( " " ), QLatin1String( "_" ) );
args.replace( QLatin1String( ":" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "/" ), QLatin1String( "_" ) );
args.replace( QLatin1String( "\n" ), QLatin1String( "_" ) );
}
#ifdef Q_OS_WIN
// Passing "urls" like "http://c:/path" to QUrl 'eats' the : after c,
// so we must restore it
if ( modifiedUrlString[1] == '/' )
{
modifiedUrlString = modifiedUrlString[0] + ":/" + modifiedUrlString.mid( 2 );
}
#endif
modifiedUrlString = modifiedUrlString.mid( 0, modifiedUrlString.indexOf( '?' ) ) + args;
QgsDebugMsg( QStringLiteral( "Get %1 (after laundering)" ).arg( modifiedUrlString ) );
modifiedUrl = QUrl::fromLocalFile( modifiedUrlString );
}

return modifiedUrl;
}

///////////////////////////////////////////////////////////////////////////////

QgsArcGisAsyncQuery::QgsArcGisAsyncQuery( QObject *parent )
Expand Down
2 changes: 2 additions & 0 deletions src/providers/arcgisrest/qgsarcgisrestutils.h
Expand Up @@ -42,6 +42,8 @@ class QgsArcGisRestUtils
const QgsRectangle &filterRect, QString &errorTitle, QString &errorText );
static QByteArray queryService( const QUrl &url, QString &errorTitle, QString &errorText );
static QVariantMap queryServiceJSON( const QUrl &url, QString &errorTitle, QString &errorText );

static QUrl parseUrl( const QUrl &url );
};

class QgsArcGisAsyncQuery : public QObject
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -9,6 +9,7 @@ IF (WITH_SERVER)
ENDIF (WITH_SERVER)

ADD_PYTHON_TEST(PyQgsActionManager test_qgsactionmanager.py)
ADD_PYTHON_TEST(PyQgsAFSProvider test_provider_afs.py)
ADD_PYTHON_TEST(PyQgsAggregateCalculator test_qgsaggregatecalculator.py)
ADD_PYTHON_TEST(PyQgsAnnotation test_qgsannotation.py)
ADD_PYTHON_TEST(PyQgsApplication test_qgsapplication.py)
Expand Down

0 comments on commit b434ab1

Please sign in to comment.