17
17
import tempfile
18
18
import shutil
19
19
20
+ # Needed on Qt 5 so that the serialization of XML is consistant among all executions
21
+ os .environ ['QT_HASH_SEED' ] = '1'
22
+
20
23
from qgis .PyQt .QtCore import Qt , QObject , QDateTime
21
24
22
25
from qgis .core import (
@@ -397,7 +400,7 @@ def testWFS10(self):
397
400
reference = QgsGeometry .fromRect (
398
401
QgsRectangle (- 71.123 , 66.33 , - 65.32 , 78.3 ))
399
402
vl_extent = QgsGeometry .fromRect (vl .extent ())
400
- assert QgsGeometry .compare (vl_extent .asPolygon (), reference .asPolygon (), 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
403
+ assert QgsGeometry .compare (vl_extent .asPolygon ()[ 0 ] , reference .asPolygon ()[ 0 ] , 0.00001 ), 'Expected {}, got {}' .format (reference .exportToWkt (), vl_extent .exportToWkt ())
401
404
402
405
with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0&TYPENAME=my:typename&SRSNAME=EPSG:4326' ), 'wb' ) as f :
403
406
f .write ("""
@@ -439,7 +442,8 @@ def testWFS10(self):
439
442
values = [f ['datetimefield' ] for f in vl .getFeatures ()]
440
443
self .assertEqual (values , [QDateTime (2016 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))])
441
444
442
- got = [f .geometry () for f in vl .getFeatures ()][0 ].geometry ()
445
+ got_f = [f for f in vl .getFeatures ()]
446
+ got = got_f [0 ].geometry ().geometry ()
443
447
self .assertEqual ((got .x (), got .y ()), (2.0 , 49.0 ))
444
448
445
449
self .assertEqual (vl .featureCount (), 1 )
@@ -521,8 +525,7 @@ def testWFST10(self):
521
525
assert not vl .dataProvider ().changeAttributeValues ({0 : {0 : 0 }})
522
526
523
527
# Test addFeatures
524
- with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Insert xmlns="http://www.opengis.net/wfs"><typename xmlns="http://my"><intfield xmlns="http://my">1</intfield><longfield xmlns="http://my">1234567890123</longfield><stringfield xmlns="http://my">foo</stringfield><datetimefield xmlns="http://my">2016-04-10T12:34:56.789Z</datetimefield><geometryProperty xmlns="http://my"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">2,49</gml:coordinates></gml:Point></geometryProperty></typename></Insert></Transaction>' ), 'wb' ) as f :
525
- f .write ("""
528
+ response = """
526
529
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
527
530
<wfs:InsertResult>
528
531
<ogc:FeatureId fid="typename.1" />
@@ -533,7 +536,14 @@ def testWFST10(self):
533
536
</wfs:Status>
534
537
</wfs:TransactionResult>
535
538
</wfs:WFS_TransactionResponse>
536
- """ .encode ('UTF-8' ))
539
+ """
540
+ # Qt 4 order
541
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Insert xmlns="http://www.opengis.net/wfs"><typename xmlns="http://my"><intfield xmlns="http://my">1</intfield><longfield xmlns="http://my">1234567890123</longfield><stringfield xmlns="http://my">foo</stringfield><datetimefield xmlns="http://my">2016-04-10T12:34:56.789Z</datetimefield><geometryProperty xmlns="http://my"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">2,49</gml:coordinates></gml:Point></geometryProperty></typename></Insert></Transaction>' ), 'wb' ) as f :
542
+ f .write (response .encode ('UTF-8' ))
543
+
544
+ # Qt 5 order
545
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" version="1.0.0"><Insert xmlns="http://www.opengis.net/wfs"><typename xmlns="http://my"><intfield xmlns="http://my">1</intfield><longfield xmlns="http://my">1234567890123</longfield><stringfield xmlns="http://my">foo</stringfield><datetimefield xmlns="http://my">2016-04-10T12:34:56.789Z</datetimefield><geometryProperty xmlns="http://my"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">2,49</gml:coordinates></gml:Point></geometryProperty></typename></Insert></Transaction>' ), 'wb' ) as f :
546
+ f .write (response .encode ('UTF-8' ))
537
547
538
548
f = QgsFeature ()
539
549
f .setAttributes ([1 , 1234567890123 , 'foo' , QDateTime (2016 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))])
@@ -556,25 +566,33 @@ def testWFST10(self):
556
566
values = [f ['datetimefield' ] for f in vl .getFeatures ()]
557
567
self .assertEqual (values , [QDateTime (2016 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))])
558
568
559
- got = [f .geometry () for f in vl .getFeatures ()][0 ].geometry ()
569
+ got_f = [f for f in vl .getFeatures ()]
570
+ got = got_f [0 ].geometry ().geometry ()
560
571
self .assertEqual ((got .x (), got .y ()), (2.0 , 49.0 ))
561
572
562
573
# Test changeGeometryValues
563
- with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">geometryProperty</Name><Value xmlns="http://www.opengis.net/wfs"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">3,50</gml:coordinates></gml:Point></Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
564
- f .write ("""
574
+ content = """
565
575
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
566
576
<wfs:TransactionResult>
567
577
<wfs:Status>
568
578
<wfs:SUCCESS/>
569
579
</wfs:Status>
570
580
</wfs:TransactionResult>
571
581
</wfs:WFS_TransactionResponse>
572
- """ .encode ('UTF-8' ))
582
+ """
583
+ # Qt 4 order
584
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">geometryProperty</Name><Value xmlns="http://www.opengis.net/wfs"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">3,50</gml:coordinates></gml:Point></Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
585
+ f .write (content .encode ('UTF-8' ))
586
+
587
+ # Qt 5 order
588
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" version="1.0.0"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">geometryProperty</Name><Value xmlns="http://www.opengis.net/wfs"><gml:Point srsName="EPSG:4326"><gml:coordinates cs="," ts=" ">3,50</gml:coordinates></gml:Point></Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
589
+ f .write (content .encode ('UTF-8' ))
573
590
574
591
ret = vl .dataProvider ().changeGeometryValues ({1 : QgsGeometry .fromWkt ('Point (3 50)' )})
575
592
assert ret
576
593
577
- got = [f .geometry () for f in vl .getFeatures ()][0 ].geometry ()
594
+ got_f = [f for f in vl .getFeatures ()]
595
+ got = got_f [0 ].geometry ().geometry ()
578
596
self .assertEqual ((got .x (), got .y ()), (3.0 , 50.0 ))
579
597
580
598
values = [f ['intfield' ] for f in vl .getFeatures ()]
@@ -590,16 +608,22 @@ def testWFST10(self):
590
608
self .assertEqual (values , [QDateTime (2016 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))])
591
609
592
610
# Test changeAttributeValues
593
- with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">intfield</Name><Value xmlns="http://www.opengis.net/wfs">2</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">longfield</Name><Value xmlns="http://www.opengis.net/wfs">3</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">stringfield</Name><Value xmlns="http://www.opengis.net/wfs">bar</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">datetimefield</Name><Value xmlns="http://www.opengis.net/wfs">2015-04-10T12:34:56.789Z</Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
594
- f .write ("""
611
+ content = """
595
612
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
596
613
<wfs:TransactionResult>
597
614
<wfs:Status>
598
615
<wfs:SUCCESS/>
599
616
</wfs:Status>
600
617
</wfs:TransactionResult>
601
618
</wfs:WFS_TransactionResponse>
602
- """ .encode ('UTF-8' ))
619
+ """
620
+ # Qt 4 order
621
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">intfield</Name><Value xmlns="http://www.opengis.net/wfs">2</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">longfield</Name><Value xmlns="http://www.opengis.net/wfs">3</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">stringfield</Name><Value xmlns="http://www.opengis.net/wfs">bar</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">datetimefield</Name><Value xmlns="http://www.opengis.net/wfs">2015-04-10T12:34:56.789Z</Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
622
+ f .write (content .encode ('UTF-8' ))
623
+ # Qt 5 order
624
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" version="1.0.0"><Update xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">intfield</Name><Value xmlns="http://www.opengis.net/wfs">2</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">longfield</Name><Value xmlns="http://www.opengis.net/wfs">3</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">stringfield</Name><Value xmlns="http://www.opengis.net/wfs">bar</Value></Property><Property xmlns="http://www.opengis.net/wfs"><Name xmlns="http://www.opengis.net/wfs">datetimefield</Name><Value xmlns="http://www.opengis.net/wfs">2015-04-10T12:34:56.789Z</Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Update></Transaction>' ), 'wb' ) as f :
625
+ f .write (content .encode ('UTF-8' ))
626
+
603
627
assert vl .dataProvider ().changeAttributeValues ({1 : {0 : 2 , 1 : 3 , 2 : "bar" , 3 : QDateTime (2015 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))}})
604
628
605
629
values = [f ['intfield' ] for f in vl .getFeatures ()]
@@ -614,20 +638,27 @@ def testWFST10(self):
614
638
values = [f ['datetimefield' ] for f in vl .getFeatures ()]
615
639
self .assertEqual (values , [QDateTime (2015 , 4 , 10 , 12 , 34 , 56 , 789 , Qt .TimeSpec (Qt .UTC ))])
616
640
617
- got = [f .geometry () for f in vl .getFeatures ()][0 ].geometry ()
641
+ got_f = [f for f in vl .getFeatures ()]
642
+ got = got_f [0 ].geometry ().geometry ()
618
643
self .assertEqual ((got .x (), got .y ()), (3.0 , 50.0 ))
619
644
620
645
# Test deleteFeatures
621
- with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Delete xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Delete></Transaction>' ), 'wb' ) as f :
622
- f .write ("""
646
+ content = """
623
647
<wfs:WFS_TransactionResponse version="1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc">
624
648
<wfs:TransactionResult>
625
649
<wfs:Status>
626
650
<wfs:SUCCESS/>
627
651
</wfs:Status>
628
652
</wfs:TransactionResult>
629
653
</wfs:WFS_TransactionResponse>
630
- """ .encode ('UTF-8' ))
654
+ """
655
+ # Qt 4 order
656
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" service="WFS" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml"><Delete xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Delete></Transaction>' ), 'wb' ) as f :
657
+ f .write (content .encode ('UTF-8' ))
658
+ # Qt 5 order
659
+ with open (sanitize (endpoint , '?SERVICE=WFS&POSTDATA=<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my http://fake_qgis_http_endpoint?REQUEST=DescribeFeatureType&VERSION=1.0.0&TYPENAME=my:typename" xmlns:my="http://my" xmlns:gml="http://www.opengis.net/gml" version="1.0.0"><Delete xmlns="http://www.opengis.net/wfs" typeName="my:typename"><Filter xmlns="http://www.opengis.net/ogc"><FeatureId xmlns="http://www.opengis.net/ogc" fid="typename.1"/></Filter></Delete></Transaction>' ), 'wb' ) as f :
660
+ f .write (content .encode ('UTF-8' ))
661
+
631
662
assert vl .dataProvider ().deleteFeatures ([1 ])
632
663
633
664
self .assertEqual (vl .featureCount (), 0 )
@@ -1310,7 +1341,7 @@ def testJoins(self):
1310
1341
# main table not appearing in first
1311
1342
1312
1343
with open (sanitize (endpoint , '?SERVICE=WFS&REQUEST=DescribeFeatureType&VERSION=2.0.0&TYPENAME=my:othertypename,my:typename' ), 'wb' ) as f :
1313
- f .write (schema )
1344
+ f .write (schema . encode ( 'UTF-8' ) )
1314
1345
1315
1346
vl = QgsVectorLayer (u"url='http://" + endpoint + u"' typename='my:typename' version='2.0.0' sql=SELECT * FROM othertypename o, typename WHERE typename.id = o.main_id AND typename.id > 0 ORDER BY typename.id DESC" , u'test' , u'WFS' )
1316
1347
assert vl .isValid ()
0 commit comments