Merge pull request #2862 from nyalldawson/server_test_gdal

Fix PyQgsServer test on GDAL >= 2.0 and fix handling of longlong types
This commit is contained in:
Nyall Dawson 2016-03-18 09:12:51 +11:00
commit 81d4d086d6
4 changed files with 16 additions and 3 deletions

View File

@ -468,6 +468,8 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle
QVariant::Type attributeType = fields[idx].type(); QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int ) if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" ); attElem.setAttribute( "type", "integer" );
else if ( attributeType == QVariant::LongLong )
attElem.setAttribute( "type", "long" );
else if ( attributeType == QVariant::Double ) else if ( attributeType == QVariant::Double )
attElem.setAttribute( "type", "double" ); attElem.setAttribute( "type", "double" );
else if ( attributeType == QVariant::Bool ) else if ( attributeType == QVariant::Bool )

View File

@ -21,6 +21,7 @@ from qgis.server import QgsServer
from qgis.core import QgsMessageLog from qgis.core import QgsMessageLog
from qgis.testing import unittest from qgis.testing import unittest
from utilities import unitTestDataPath from utilities import unitTestDataPath
import osgeo.gdal
# Strip path and content length because path may vary # Strip path and content length because path may vary
RE_STRIP_PATH = r'MAP=[^&]+|Content-Length: \d+' RE_STRIP_PATH = r'MAP=[^&]+|Content-Length: \d+'
@ -163,6 +164,11 @@ class TestQgsServer(unittest.TestCase):
""" """
response = re.sub(RE_STRIP_PATH, '', response) response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected) 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)) 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): def test_project_wms(self):
@ -240,10 +246,15 @@ class TestQgsServer(unittest.TestCase):
""" """
response = re.sub(RE_STRIP_PATH, '', response) response = re.sub(RE_STRIP_PATH, '', response)
expected = re.sub(RE_STRIP_PATH, '', expected) 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)) 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): def test_project_wfs(self):
"""Test some WMS request""" """Test some WFS request"""
for request in ('GetCapabilities', 'DescribeFeatureType'): for request in ('GetCapabilities', 'DescribeFeatureType'):
self.wfs_request_compare(request) self.wfs_request_compare(request)

View File

@ -150,7 +150,7 @@ Content-Type: text/xml; charset=utf-8
</Style> </Style>
<TreeName>testlayer èé</TreeName> <TreeName>testlayer èé</TreeName>
<Attributes> <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="10" editType="TextEdit" type="QString" comment="" name="name"/>
<Attribute typeName="String" precision="0" length="13" editType="TextEdit" type="QString" comment="" name="utf8nameè"/> <Attribute typeName="String" precision="0" length="13" editType="TextEdit" type="QString" comment="" name="utf8nameè"/>
</Attributes> </Attributes>

View File

@ -9,7 +9,7 @@ Content-Type: text/xml; charset=utf-8
<extension base="gml:AbstractFeatureType"> <extension base="gml:AbstractFeatureType">
<sequence> <sequence>
<element minOccurs="0" maxOccurs="1" type="gml:GeometryPropertyType" name="geometry"/> <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="name"/>
<element type="string" name="utf8nameè"/> <element type="string" name="utf8nameè"/>
</sequence> </sequence>