Skip to content
Permalink
Browse files

[afs] Add unit test for metadata

  • Loading branch information
nyalldawson committed Feb 20, 2018
1 parent f7559d3 commit 5145b2c2a32e61c2265444a790c1b8419316c781
Showing with 67 additions and 8 deletions.
  1. +7 −0 src/providers/arcgisrest/qgsafsprovider.cpp
  2. +60 −8 tests/src/python/test_provider_afs.py
@@ -193,6 +193,13 @@ QgsAfsProvider::QgsAfsProvider( const QString &uri )
// layer metadata

mLayerMetadata.setIdentifier( mSharedData->mDataSource.param( QStringLiteral( "url" ) ) );
const QString parentIdentifier = layerData[QStringLiteral( "parentLayer" )].toMap().value( QStringLiteral( "id" ) ).toString();
if ( !parentIdentifier.isEmpty() )
{
const QString childUrl = mSharedData->mDataSource.param( QStringLiteral( "url" ) );
const QString parentUrl = childUrl.left( childUrl.lastIndexOf( '/' ) ) + '/' + parentIdentifier;
mLayerMetadata.setParentIdentifier( parentUrl );
}
mLayerMetadata.setType( QStringLiteral( "dataset" ) );
mLayerMetadata.setAbstract( mLayerDescription );
mLayerMetadata.setTitle( mLayerName );
@@ -21,16 +21,13 @@
from qgis.PyQt.QtCore import QCoreApplication, Qt, QObject, QDateTime

from qgis.core import (
QgsWkbTypes,
QgsVectorLayer,
QgsFeature,
QgsGeometry,
QgsRectangle,
QgsPointXY,
QgsVectorDataProvider,
QgsFeatureRequest,
QgsLayerMetadata,
QgsBox3d,
QgsCoordinateReferenceSystem,
QgsApplication,
QgsSettings
QgsSettings,
QgsRectangle
)
from qgis.testing import (start_app,
unittest
@@ -407,6 +404,61 @@ def testObjectIdDifferentName(self):
vl = QgsVectorLayer("url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver')
assert vl.isValid()

def testMetadata(self):
""" Test that metadata is correctly acquired from provider """

endpoint = self.basetestpath + '/metadata_fake_qgis_http_endpoint'
with open(sanitize(endpoint, '?f=json'), 'wb') as f:
f.write("""
{"currentVersion":10.22,"id":1,"name":"QGIS Test","type":"Feature Layer","description":
"QGIS Provider Test Layer","geometryType":"esriGeometryPoint","copyrightText":"not copyright","parentLayer":{"id":2,"name":"QGIS Tests"},"subLayers":[],
"minScale":72225,"maxScale":0,
"defaultVisibility":true,
"extent":{"xmin":-71.123,"ymin":66.33,"xmax":-65.32,"ymax":78.3,
"spatialReference":{"wkid":4326,"latestWkid":4326}},
"hasAttachments":false,"htmlPopupType":"esriServerHTMLPopupTypeAsHTMLText",
"displayField":"LABEL","typeIdField":null,
"fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null}],
"relationships":[],"canModifyLayer":false,"canScaleSymbols":false,"hasLabels":false,
"capabilities":"Map,Query,Data","maxRecordCount":1000,"supportsStatistics":true,
"supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF",
"ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""".encode(
'UTF-8'))

with open(sanitize(endpoint, '/query?f=json_where=OBJECTID=OBJECTID_returnIdsOnly=true'), 'wb') as f:
f.write("""
{
"objectIdFieldName": "OBJECTID",
"objectIds": [
1
]
}
""".encode('UTF-8'))

# Create test layer
vl = QgsVectorLayer("url='http://" + endpoint + "' crs='epsg:4326'", 'test', 'arcgisfeatureserver')
self.assertTrue(vl.isValid())

extent = QgsLayerMetadata.Extent()
extent1 = QgsLayerMetadata.SpatialExtent()
extent1.extentCrs = QgsCoordinateReferenceSystem.fromEpsgId(4326)
extent1.bounds = QgsBox3d(QgsRectangle(-71.123, 66.33, -65.32, 78.3))
extent.setSpatialExtents([extent1])
self.assertEqual(vl.metadata().extent(), extent)

self.assertEqual(vl.metadata().crs(), QgsCoordinateReferenceSystem.fromEpsgId(4326))
self.assertEqual(vl.metadata().identifier(), 'http://' + sanitize(endpoint, ''))
self.assertEqual(vl.metadata().parentIdentifier(), 'http://' + self.basetestpath + '/2')
self.assertEqual(vl.metadata().type(), 'dataset')
self.assertEqual(vl.metadata().abstract(), 'QGIS Provider Test Layer')
self.assertEqual(vl.metadata().title(), 'QGIS Test')
self.assertEqual(vl.metadata().rights(), ['not copyright'])
l = QgsLayerMetadata.Link()
l.name = 'Source'
l.type = 'WWW:LINK'
l.url = 'http://' + sanitize(endpoint, '')
self.assertEqual(vl.metadata().links(), [l])


if __name__ == '__main__':
unittest.main()

0 comments on commit 5145b2c

Please sign in to comment.
You can’t perform that action at this time.