Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix PyQgsServer test on GDAL >= 2.0
Also fix handling of longlong types in wfs_describefeaturetype

(cherry-picked from 0780527)
  • Loading branch information
nyalldawson committed Mar 19, 2016
1 parent 08a1b07 commit 8ee2e2c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/server/qgswfsprojectparser.cpp
Expand Up @@ -468,6 +468,8 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" );
else if ( attributeType == QVariant::LongLong )
attElem.setAttribute( "type", "long" );
else if ( attributeType == QVariant::Double )
attElem.setAttribute( "type", "double" );
else if ( attributeType == QVariant::Bool )
Expand Down
13 changes: 12 additions & 1 deletion tests/src/python/test_qgsserver.py
Expand Up @@ -21,6 +21,7 @@
from qgis.core import QgsMessageLog
from qgis.testing import unittest
from utilities import unitTestDataPath
import osgeo.gdal

# Strip path and content length because path may vary
RE_STRIP_PATH = r'MAP=[^&]+|Content-Length: \d+'
Expand Down Expand Up @@ -163,6 +164,11 @@ def wms_request_compare(self, request, extra=None, reference_file=None):
"""
response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected)

# for older GDAL versions (<2.0), id field will be integer type
if int(osgeo.gdal.VersionInfo()[:1]) < 2:
expected = expected.replace('typeName="Integer64" precision="0" length="10" editType="TextEdit" type="qlonglong"', 'typeName="Integer" precision="0" length="10" editType="TextEdit" type="int"')

self.assertEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected, response))

def test_project_wms(self):
Expand Down Expand Up @@ -240,10 +246,15 @@ def wfs_request_compare(self, request):
"""
response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected)

# for older GDAL versions (<2.0), id field will be integer type
if int(osgeo.gdal.VersionInfo()[:1]) < 2:
expected = expected.replace('<element type="long" name="id"/>', '<element type="integer" name="id"/>')

self.assertEqual(response, expected, msg="request %s failed.\n Query: %s\n Expected:\n%s\n\n Response:\n%s" % (query_string, request, expected, response))

def test_project_wfs(self):
"""Test some WMS request"""
"""Test some WFS request"""
for request in ('GetCapabilities', 'DescribeFeatureType'):
self.wfs_request_compare(request)

Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server/getprojectsettings.txt
Expand Up @@ -150,7 +150,7 @@ Content-Type: text/xml; charset=utf-8
</Style>
<TreeName>testlayer èé</TreeName>
<Attributes>
<Attribute typeName="Integer" precision="0" length="10" editType="TextEdit" type="int" comment="" name="id"/>
<Attribute typeName="Integer64" precision="0" length="10" editType="TextEdit" type="qlonglong" comment="" name="id"/>
<Attribute typeName="String" precision="0" length="10" editType="TextEdit" type="QString" comment="" name="name"/>
<Attribute typeName="String" precision="0" length="13" editType="TextEdit" type="QString" comment="" name="utf8nameè"/>
</Attributes>
Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/qgis_server/wfs_describefeaturetype.txt
Expand Up @@ -9,7 +9,7 @@ Content-Type: text/xml; charset=utf-8
<extension base="gml:AbstractFeatureType">
<sequence>
<element minOccurs="0" maxOccurs="1" type="gml:GeometryPropertyType" name="geometry"/>
<element type="integer" name="id"/>
<element type="long" name="id"/>
<element type="string" name="name"/>
<element type="string" name="utf8nameè"/>
</sequence>
Expand Down

0 comments on commit 8ee2e2c

Please sign in to comment.