Skip to content

Commit

Permalink
Address PR comments + test assets to temp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 12, 2019
1 parent e818fc6 commit b1ac605
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/server/qgsrequesthandler.cpp
Expand Up @@ -214,12 +214,12 @@ void QgsRequestHandler::parseInput()

typedef QPair<QString, QString> pair_t;
QUrlQuery query( inputString );
QList<pair_t> items = query.queryItems();
for ( pair_t pair : items )
const QList<pair_t> items = query.queryItems();
for ( const pair_t &pair : items )
{
// QUrl::fromPercentEncoding doesn't replace '+' with space
const QString key = QUrl::fromPercentEncoding( pair.first.replace( '+', ' ' ).toUtf8() );
const QString value = QUrl::fromPercentEncoding( pair.second.replace( '+', ' ' ).toUtf8() );
const QString key = QUrl::fromPercentEncoding( QString( pair.first ).replace( '+', ' ' ).toUtf8() );
const QString value = QUrl::fromPercentEncoding( QString( pair.second ).replace( '+', ' ' ).toUtf8() );
mRequest.setParameter( key.toUpper(), value );
}
setupParameters();
Expand Down
7 changes: 4 additions & 3 deletions src/server/services/wfs3/qgswfs3handlers.cpp
Expand Up @@ -1304,8 +1304,6 @@ void QgsWfs3CollectionsItemsHandler::handleRequest( const QgsServerApiContext &c
break;
}
}
// This should never happen!
Q_ASSERT( !selfLink.is_null() );

// Add prev - next links
if ( offset != 0 )
Expand Down Expand Up @@ -1822,7 +1820,10 @@ void QgsWfs3CollectionsFeatureHandler::handleRequest( const QgsServerApiContext
throw QgsServerApiBadRequestException( QStringLiteral( "Feature properties are not valid" ) );
}

// TODO: raise if nothing to change?
if ( changedAttributes.isEmpty() && changedGeometries.isEmpty() )
{
QgsMessageLog::logMessage( QStringLiteral( "Changeset is empty: no features have been modified" ), QStringLiteral( "Server" ), Qgis::Info );
}

if ( ! mapLayer->dataProvider()->changeFeatures( changedAttributes, changedGeometries ) )
{
Expand Down
46 changes: 33 additions & 13 deletions tests/src/python/test_qgsserver_api.py
Expand Up @@ -98,8 +98,15 @@ def test_append_path(self):
def test_temporal_extent(self):

project = QgsProject()
base_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs'
project.read(base_path)

tempDir = QtCore.QTemporaryDir()
source_project_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs'
source_data_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.gpkg'
dest_project_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.qgs')
dest_data_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.gpkg')
shutil.copy(source_data_path, dest_data_path)
shutil.copy(source_project_path, dest_project_path)
project.read(dest_project_path)

layer = list(project.mapLayers().values())[0]

Expand Down Expand Up @@ -409,7 +416,14 @@ def test_wfs3_collection_json(self):
def test_wfs3_collection_temporal_extent_json(self):
"""Test collection with timefilter"""
project = QgsProject()
project.read(unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs')
tempDir = QtCore.QTemporaryDir()
source_project_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs'
source_data_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.gpkg'
dest_project_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.qgs')
dest_data_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.gpkg')
shutil.copy(source_data_path, dest_data_path)
shutil.copy(source_project_path, dest_project_path)
project.read(dest_project_path)
request = QgsBufferServerRequest('http://server.qgis.org/wfs3/collections/points')
self.compareApi(request, project, 'test_wfs3_collection_points_timefilters.json')

Expand Down Expand Up @@ -955,25 +969,31 @@ def test_wfs3_time_filters_ranges(self):
"""Test datetime filters"""

project = QgsProject()
base_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs'
project.read(base_path)

tempDir = QtCore.QTemporaryDir()
source_project_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.qgs'
source_data_path = unitTestDataPath('qgis_server') + '/test_project_api_timefilters.gpkg'
dest_project_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.qgs')
dest_data_path = os.path.join(tempDir.path(), 'test_project_api_timefilters.gpkg')
shutil.copy(source_data_path, dest_data_path)
shutil.copy(source_project_path, dest_project_path)
project.read(dest_project_path)

# Prepare projects with all options
tmpDir = QtCore.QTemporaryDir()

layer = list(project.mapLayers().values())[0]
layer.serverProperties().removeWmsDimension('date')
layer.serverProperties().removeWmsDimension('time')
self.assertEqual(len(layer.serverProperties().wmsDimensions()), 0)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 0)
none_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_none.qgs')
none_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_none.qgs')
project.write(none_path)

layer = list(project.mapLayers().values())[0]
layer.serverProperties().removeWmsDimension('date')
layer.serverProperties().removeWmsDimension('time')
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('date', 'created')))
created_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_created.qgs')
created_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_created.qgs')
project.write(created_path)
project.read(created_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 1)
Expand All @@ -982,7 +1002,7 @@ def test_wfs3_time_filters_ranges(self):
layer.serverProperties().removeWmsDimension('date')
layer.serverProperties().removeWmsDimension('time')
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('date', 'created_string')))
created_string_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_created_string.qgs')
created_string_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_created_string.qgs')
project.write(created_string_path)
project.read(created_string_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 1)
Expand All @@ -991,7 +1011,7 @@ def test_wfs3_time_filters_ranges(self):
layer.serverProperties().removeWmsDimension('date')
layer.serverProperties().removeWmsDimension('time')
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('time', 'updated_string')))
updated_string_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_updated_string.qgs')
updated_string_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_updated_string.qgs')
project.write(updated_string_path)
project.read(updated_string_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 1)
Expand All @@ -1001,7 +1021,7 @@ def test_wfs3_time_filters_ranges(self):
layer.serverProperties().removeWmsDimension('time')
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 0)
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('time', 'updated')))
updated_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_updated.qgs')
updated_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_updated.qgs')
project.write(updated_path)
project.read(updated_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 1)
Expand All @@ -1012,7 +1032,7 @@ def test_wfs3_time_filters_ranges(self):
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 0)
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('time', 'updated')))
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('date', 'created')))
both_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_both.qgs')
both_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_both.qgs')
project.write(both_path)
project.read(both_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 2)
Expand All @@ -1021,7 +1041,7 @@ def test_wfs3_time_filters_ranges(self):
layer.serverProperties().removeWmsDimension('date')
layer.serverProperties().removeWmsDimension('time')
self.assertTrue(layer.serverProperties().addWmsDimension(QgsVectorLayerServerProperties.WmsDimensionInfo('date', 'begin', 'end')))
date_range_path = os.path.join(tmpDir.path(), 'test_project_api_timefilters_date_range.qgs')
date_range_path = os.path.join(tempDir.path(), 'test_project_api_timefilters_date_range.qgs')
project.write(date_range_path)
project.read(date_range_path)
self.assertEqual(len(project.mapLayersByName('points')[0].serverProperties().wmsDimensions()), 1)
Expand Down

0 comments on commit b1ac605

Please sign in to comment.