mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
add tests and fix spellcheck (compatiblity by compatibility)
This commit is contained in:
parent
60db820f19
commit
9b0bb2ffb5
@ -62,7 +62,9 @@ Constructor from a QDomElement ``element``
|
||||
|
||||
bool updateSettings( QgsSettings &settings, const QString &key = QString() ) const;
|
||||
%Docstring
|
||||
Updates the ``settings`` by adding all the http headers in the path "key/KEY_PREFIX/"
|
||||
Updates the ``settings`` by adding all the http headers in the path "key/PATH_PREFIX/"
|
||||
|
||||
KEY_REFERER value will be available at path "key/PATH_PREFIX/KEY_REFERER" and path "key/KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:param settings:
|
||||
:param key: sub group path
|
||||
@ -88,6 +90,8 @@ Updates an ``uri`` by adding all the HTTP headers
|
||||
%Docstring
|
||||
Updates a ``map`` by adding all the HTTP headers
|
||||
|
||||
KEY_REFERER value will be available at key "KEY_PREFIX+KEY_REFERER" and key "KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:return: ``True`` if the update succeed
|
||||
%End
|
||||
|
||||
@ -95,6 +99,8 @@ Updates a ``map`` by adding all the HTTP headers
|
||||
%Docstring
|
||||
Updates a ``map`` by adding all the HTTP headers
|
||||
|
||||
KEY_REFERER value will be available at attribute "KEY_PREFIX+KEY_REFERER" and attribute "KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:return: ``True`` if the update succeed
|
||||
%End
|
||||
|
||||
@ -102,6 +108,8 @@ Updates a ``map`` by adding all the HTTP headers
|
||||
%Docstring
|
||||
Loads headers from the ``settings``
|
||||
|
||||
key KEY_REFERER will be read at path "key/PATH_PREFIX/KEY_REFERER" and path "key/KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:param settings:
|
||||
:param key: sub group path
|
||||
%End
|
||||
@ -117,6 +125,8 @@ Loads headers from the ``uri``
|
||||
%Docstring
|
||||
Loads headers from the ``map``
|
||||
|
||||
key KEY_REFERER will be read from key "KEY_PREFIX+KEY_REFERER" and key "KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:param map:
|
||||
%End
|
||||
|
||||
@ -124,6 +134,8 @@ Loads headers from the ``map``
|
||||
%Docstring
|
||||
Loads headers from the ``element``
|
||||
|
||||
key KEY_REFERER will be read from attribute "KEY_PREFIX+KEY_REFERER" and attribute "KEY_REFERER" (for backward compatibility)
|
||||
|
||||
:param element:
|
||||
%End
|
||||
|
||||
|
@ -360,11 +360,15 @@ Returns parameter keys used in the uri: specialized ones ("table", "schema", etc
|
||||
QgsHttpHeaders &httpHeaders();
|
||||
%Docstring
|
||||
Returns http headers
|
||||
|
||||
.. versionadded:: 3.26
|
||||
%End
|
||||
|
||||
QString httpHeader( const QString &key );
|
||||
%Docstring
|
||||
Returns the http header value according to ``key``
|
||||
|
||||
.. versionadded:: 3.26
|
||||
%End
|
||||
|
||||
void setHttpHeaders( const QgsHttpHeaders &headers );
|
||||
@ -382,7 +386,6 @@ Sets headers to ``headers``
|
||||
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* This file has been generated automatically from *
|
||||
* *
|
||||
|
@ -94,6 +94,7 @@ bool QgsHttpHeaders::updateSettings( QgsSettings &settings, const QString &key )
|
||||
settings.setValue( keyFixed + QgsHttpHeaders::KEY_REFERER, mHeaders[QgsHttpHeaders::KEY_REFERER].toString() );
|
||||
}
|
||||
|
||||
// TODO REMOVE!
|
||||
#if 0
|
||||
QgsLogger::debug( QString( "updateSettings key: %1" ).arg( keyFixed ) );
|
||||
for ( auto k : settings.allKeys() )
|
||||
@ -198,7 +199,7 @@ void QgsHttpHeaders::setFromMap( const QVariantMap &map )
|
||||
}
|
||||
}
|
||||
|
||||
if ( map.contains( QgsHttpHeaders::KEY_REFERER ) )
|
||||
if ( map.contains( QgsHttpHeaders::KEY_REFERER ) ) // backward comptibility
|
||||
{
|
||||
mHeaders[QgsHttpHeaders::KEY_REFERER] = map [QgsHttpHeaders::KEY_REFERER].toString();
|
||||
}
|
||||
@ -208,6 +209,7 @@ void QgsHttpHeaders::setFromMap( const QVariantMap &map )
|
||||
void QgsHttpHeaders::setFromDomElement( const QDomElement &el )
|
||||
{
|
||||
QDomNamedNodeMap attribs = el.attributes();
|
||||
|
||||
for ( int i = 0; i < attribs.length(); i++ )
|
||||
{
|
||||
QDomNode item = attribs.item( i );
|
||||
@ -219,10 +221,11 @@ void QgsHttpHeaders::setFromDomElement( const QDomElement &el )
|
||||
}
|
||||
}
|
||||
|
||||
if ( attribs.contains( QgsHttpHeaders::KEY_REFERER ) )
|
||||
if ( attribs.contains( QgsHttpHeaders::KEY_REFERER ) ) // backward comptibility
|
||||
{
|
||||
mHeaders[QgsHttpHeaders::KEY_REFERER] = attribs.namedItem( QgsHttpHeaders::KEY_REFERER ).nodeValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString QgsHttpHeaders::toSpacedString() const
|
||||
|
@ -86,7 +86,10 @@ class CORE_EXPORT QgsHttpHeaders
|
||||
virtual ~QgsHttpHeaders();
|
||||
|
||||
/**
|
||||
* \brief Updates the \a settings by adding all the http headers in the path "key/KEY_PREFIX/"
|
||||
* \brief Updates the \a settings by adding all the http headers in the path "key/PATH_PREFIX/"
|
||||
*
|
||||
* KEY_REFERER value will be available at path "key/PATH_PREFIX/KEY_REFERER" and path "key/KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \param settings
|
||||
* \param key sub group path
|
||||
* \return TRUE if the update succeed
|
||||
@ -107,18 +110,27 @@ class CORE_EXPORT QgsHttpHeaders
|
||||
|
||||
/**
|
||||
* \brief Updates a \a map by adding all the HTTP headers
|
||||
*
|
||||
* KEY_REFERER value will be available at key "KEY_PREFIX+KEY_REFERER" and key "KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \return TRUE if the update succeed
|
||||
*/
|
||||
bool updateMap( QVariantMap &map ) const;
|
||||
|
||||
/**
|
||||
* \brief Updates a \a map by adding all the HTTP headers
|
||||
*
|
||||
* KEY_REFERER value will be available at attribute "KEY_PREFIX+KEY_REFERER" and attribute "KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \return TRUE if the update succeed
|
||||
*/
|
||||
bool updateDomElement( QDomElement &el ) const;
|
||||
|
||||
/**
|
||||
* \brief Loads headers from the \a settings
|
||||
*
|
||||
* key KEY_REFERER will be read at path "key/PATH_PREFIX/KEY_REFERER" and path "key/KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \param settings
|
||||
* \param key sub group path
|
||||
*/
|
||||
@ -132,12 +144,18 @@ class CORE_EXPORT QgsHttpHeaders
|
||||
|
||||
/**
|
||||
* \brief Loads headers from the \a map
|
||||
*
|
||||
* key KEY_REFERER will be read from key "KEY_PREFIX+KEY_REFERER" and key "KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \param map
|
||||
*/
|
||||
void setFromMap( const QVariantMap &map );
|
||||
|
||||
/**
|
||||
* \brief Loads headers from the \a element
|
||||
*
|
||||
* key KEY_REFERER will be read from attribute "KEY_PREFIX+KEY_REFERER" and attribute "KEY_REFERER" (for backward compatibility)
|
||||
*
|
||||
* \param element
|
||||
*/
|
||||
void setFromDomElement( const QDomElement &element );
|
||||
|
@ -331,10 +331,16 @@ class CORE_EXPORT QgsDataSourceUri
|
||||
QgsHttpHeaders httpHeaders() const { return mHttpHeaders; }
|
||||
#endif
|
||||
|
||||
//! Returns http headers
|
||||
/**
|
||||
* Returns http headers
|
||||
* \since QGIS 3.26
|
||||
*/
|
||||
QgsHttpHeaders &httpHeaders() { return mHttpHeaders; }
|
||||
|
||||
//! Returns the http header value according to \a key
|
||||
/**
|
||||
* Returns the http header value according to \a key
|
||||
* \since QGIS 3.26
|
||||
*/
|
||||
QString httpHeader( const QString &key ) { return mHttpHeaders[key].toString(); }
|
||||
|
||||
/**
|
||||
@ -403,4 +409,3 @@ class CORE_EXPORT QgsDataSourceUri
|
||||
};
|
||||
|
||||
#endif //QGSDATASOURCEURI_H
|
||||
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include <qgspoint.h>
|
||||
#include "qgslogger.h"
|
||||
#include "qgsowsconnection.h"
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrlQuery>
|
||||
|
||||
class TestQgsHttpheaders: public QObject
|
||||
{
|
||||
@ -39,10 +41,17 @@ class TestQgsHttpheaders: public QObject
|
||||
void cleanup() {} // will be called after every testfunction.
|
||||
|
||||
void sanitize();
|
||||
|
||||
void setFromSettingsGoodKey();
|
||||
void setFromSettingsBadKey();
|
||||
void updateSettings();
|
||||
|
||||
void createQgsOwsConnection();
|
||||
|
||||
void updateNetworkRequest();
|
||||
void updateSetUrlQuery();
|
||||
void updateSetMap();
|
||||
void updateSetDomElement();
|
||||
};
|
||||
|
||||
void TestQgsHttpheaders::initTestCase()
|
||||
@ -141,5 +150,107 @@ void TestQgsHttpheaders::createQgsOwsConnection()
|
||||
QCOMPARE( uri2.encodedUri(), "https://www.ogc.org/?p1=v1&http-header:other_http_header=value&http-header:referer=http://test.com" );
|
||||
}
|
||||
|
||||
|
||||
void TestQgsHttpheaders::updateNetworkRequest()
|
||||
{
|
||||
const QUrl url( "http://ogc.org" );
|
||||
QNetworkRequest request( url );
|
||||
QgsHttpHeaders h( QVariantMap( { {QStringLiteral( "key1" ), "value1"}, {QgsHttpHeaders::KEY_REFERER, "my_ref"}} ) );
|
||||
h.updateNetworkRequest( request );
|
||||
|
||||
QVERIFY( request.hasRawHeader( "key1" ) );
|
||||
QCOMPARE( request.rawHeader( "key1" ), "value1" );
|
||||
|
||||
QVERIFY( request.hasRawHeader( QByteArray::fromStdString( QgsHttpHeaders::KEY_REFERER.toStdString() ) ) );
|
||||
QCOMPARE( request.rawHeader( QByteArray::fromStdString( QgsHttpHeaders::KEY_REFERER.toStdString() ) ), "my_ref" );
|
||||
}
|
||||
|
||||
|
||||
void TestQgsHttpheaders::updateSetUrlQuery()
|
||||
{
|
||||
QUrlQuery url( "http://ogc.org" );
|
||||
// === update
|
||||
QgsHttpHeaders h( QVariantMap( { {QStringLiteral( "key1" ), "value1"}, {QgsHttpHeaders::KEY_REFERER, "my_ref"}} ) );
|
||||
h.updateUrlQuery( url );
|
||||
|
||||
QVERIFY( url.hasQueryItem( QgsHttpHeaders::PARAM_PREFIX + "key1" ) );
|
||||
QCOMPARE( url.queryItemValue( QgsHttpHeaders::PARAM_PREFIX + "key1" ), "value1" );
|
||||
|
||||
QVERIFY( url.hasQueryItem( QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( url.queryItemValue( QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER ), "my_ref" );
|
||||
|
||||
// TODO mandatory or not?
|
||||
/*QVERIFY( url.hasQueryItem( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( url.queryItemValue( QgsHttpHeaders::KEY_REFERER ), "my_ref" );*/
|
||||
|
||||
// === setFrom
|
||||
QgsHttpHeaders h2;
|
||||
/* url.removeQueryItem(QgsHttpHeaders::KEY_REFERER);
|
||||
url.addQueryItem( QgsHttpHeaders::KEY_REFERER, "my_ref_root" ); // overwrite root ref to ckeck backward compatibility
|
||||
*/
|
||||
h2.setFromUrlQuery( url );
|
||||
QVERIFY( h2.keys().contains( QStringLiteral( "key1" ) ) );
|
||||
QCOMPARE( h2 [ QStringLiteral( "key1" ) ].toString(), QStringLiteral( "value1" ) );
|
||||
QVERIFY( h2.keys().contains( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( h2 [QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "my_ref" ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestQgsHttpheaders::updateSetMap()
|
||||
{
|
||||
QVariantMap map;
|
||||
// === update
|
||||
QgsHttpHeaders h( QVariantMap( { {QStringLiteral( "key1" ), "value1"}, {QgsHttpHeaders::KEY_REFERER, "my_ref"}} ) );
|
||||
h.updateMap( map );
|
||||
|
||||
QVERIFY( map.contains( QgsHttpHeaders::PARAM_PREFIX + "key1" ) );
|
||||
QCOMPARE( map[QgsHttpHeaders::PARAM_PREFIX + "key1"], "value1" );
|
||||
|
||||
QVERIFY( map.contains( QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( map[QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER], "my_ref" );
|
||||
|
||||
QVERIFY( map.contains( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( map[QgsHttpHeaders::KEY_REFERER], "my_ref" );
|
||||
|
||||
// === setFrom
|
||||
QgsHttpHeaders h2;
|
||||
map[QgsHttpHeaders::KEY_REFERER] = "my_ref_root"; // overwrite root ref to ckeck backward compatibility
|
||||
h2.setFromMap( map );
|
||||
QVERIFY( h2.keys().contains( QStringLiteral( "key1" ) ) );
|
||||
QCOMPARE( h2 [ QStringLiteral( "key1" ) ].toString(), QStringLiteral( "value1" ) );
|
||||
QVERIFY( h2.keys().contains( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( h2 [QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "my_ref_root" ) );
|
||||
}
|
||||
|
||||
|
||||
void TestQgsHttpheaders::updateSetDomElement()
|
||||
{
|
||||
QDomDocument doc( QStringLiteral( "connections" ) );
|
||||
QDomElement element = doc.createElement( "qgs" );
|
||||
// === update
|
||||
QgsHttpHeaders h( QVariantMap( { {QStringLiteral( "key1" ), "value1"}, {QgsHttpHeaders::KEY_REFERER, "my_ref"}} ) );
|
||||
h.updateDomElement( element );
|
||||
|
||||
QVERIFY( element.hasAttribute( QgsHttpHeaders::PARAM_PREFIX + "key1" ) );
|
||||
QCOMPARE( element.attribute( QgsHttpHeaders::PARAM_PREFIX + "key1" ), "value1" );
|
||||
|
||||
QVERIFY( element.hasAttribute( QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( element.attribute( QgsHttpHeaders::PARAM_PREFIX + QgsHttpHeaders::KEY_REFERER ), "my_ref" );
|
||||
|
||||
// TODO mandatory or not?
|
||||
QVERIFY( element.hasAttribute( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( element.attribute( QgsHttpHeaders::KEY_REFERER ), "my_ref" );
|
||||
|
||||
// === setFrom
|
||||
QgsHttpHeaders h2;
|
||||
element.setAttribute( QgsHttpHeaders::KEY_REFERER, "my_ref_root" ); // overwrite root ref to ckeck backward compatibility
|
||||
h2.setFromDomElement( element );
|
||||
QVERIFY( h2.keys().contains( QStringLiteral( "key1" ) ) );
|
||||
QCOMPARE( h2 [ QStringLiteral( "key1" ) ].toString(), QStringLiteral( "value1" ) );
|
||||
QVERIFY( h2.keys().contains( QgsHttpHeaders::KEY_REFERER ) );
|
||||
QCOMPARE( h2 [QgsHttpHeaders::KEY_REFERER ].toString(), QStringLiteral( "my_ref_root" ) );
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsHttpheaders )
|
||||
#include "testqgshttpheaders.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user