@@ -404,6 +404,91 @@ def testObjectIdDifferentName(self):
404
404
vl = QgsVectorLayer ("url='http://" + endpoint + "' crs='epsg:4326'" , 'test' , 'arcgisfeatureserver' )
405
405
assert vl .isValid ()
406
406
407
+ def testDateTime (self ):
408
+ """ Test that datetime fields work correctly """
409
+
410
+ endpoint = self .basetestpath + '/oid_fake_qgis_http_endpoint'
411
+ with open (sanitize (endpoint , '?f=json' ), 'wb' ) as f :
412
+ f .write ("""
413
+ {"currentVersion":10.22,"id":1,"name":"QGIS Test","type":"Feature Layer","description":
414
+ "QGIS Provider Test Layer.\n ","geometryType":"esriGeometryPoint","copyrightText":"","parentLayer":{"id":0,"name":"QGIS Tests"},"subLayers":[],
415
+ "minScale":72225,"maxScale":0,
416
+ "defaultVisibility":true,
417
+ "extent":{"xmin":-71.123,"ymin":66.33,"xmax":-65.32,"ymax":78.3,
418
+ "spatialReference":{"wkid":4326,"latestWkid":4326}},
419
+ "hasAttachments":false,"htmlPopupType":"esriServerHTMLPopupTypeAsHTMLText",
420
+ "displayField":"LABEL","typeIdField":null,
421
+ "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null},
422
+ {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null},
423
+ {"name":"dt","type":"esriFieldTypeDate","alias":"dt","length":8,"domain":null}],
424
+ "relationships":[],"canModifyLayer":false,"canScaleSymbols":false,"hasLabels":false,
425
+ "capabilities":"Map,Query,Data","maxRecordCount":1000,"supportsStatistics":true,
426
+ "supportsAdvancedQueries":true,"supportedQueryFormats":"JSON, AMF",
427
+ "ownershipBasedAccessControlForFeatures":{"allowOthersToQuery":true},"useStandardizedQueries":true}""" .encode (
428
+ 'UTF-8' ))
429
+
430
+ with open (sanitize (endpoint , '/query?f=json_where=OBJECTID=OBJECTID_returnIdsOnly=true' ), 'wb' ) as f :
431
+ f .write ("""
432
+ {
433
+ "objectIdFieldName": "OBJECTID",
434
+ "objectIds": [
435
+ 1,
436
+ 2
437
+ ]
438
+ }
439
+ """ .encode ('UTF-8' ))
440
+
441
+ # Create test layer
442
+ vl = QgsVectorLayer ("url='http://" + endpoint + "' crs='epsg:4326'" , 'test' , 'arcgisfeatureserver' )
443
+
444
+ self .assertTrue (vl .isValid ())
445
+ with open (sanitize (endpoint ,
446
+ '/query?f=json&objectIds=1,2&inSR=4326&outSR=4326&returnGeometry=true&outFields=OBJECTID,pk,dt&returnM=false&returnZ=false' ), 'wb' ) as f :
447
+ f .write ("""
448
+ {
449
+ "displayFieldName": "name",
450
+ "fieldAliases": {
451
+ "name": "name"
452
+ },
453
+ "geometryType": "esriGeometryPoint",
454
+ "spatialReference": {
455
+ "wkid": 4326,
456
+ "latestWkid": 4326
457
+ },
458
+ "fields":[{"name":"OBJECTID","type":"esriFieldTypeOID","alias":"OBJECTID","domain":null},
459
+ {"name":"pk","type":"esriFieldTypeInteger","alias":"pk","domain":null},
460
+ {"name":"dt","type":"esriFieldTypeDate","alias":"dt","domain":null},
461
+ {"name":"Shape","type":"esriFieldTypeGeometry","alias":"Shape","domain":null}],
462
+ "features": [
463
+ {
464
+ "attributes": {
465
+ "OBJECTID": 1,
466
+ "pk": 1,
467
+ "dt":1493769600000
468
+ },
469
+ "geometry": {
470
+ "x": -70.332,
471
+ "y": 66.33
472
+ }
473
+ },
474
+ {
475
+ "attributes": {
476
+ "OBJECTID": 2,
477
+ "pk": 2,
478
+ "dt":null
479
+ },
480
+ "geometry": {
481
+ "x": -68.2,
482
+ "y": 70.8
483
+ }
484
+ }
485
+ ]
486
+ }""" .encode ('UTF-8' ))
487
+
488
+ features = [f for f in vl .getFeatures ()]
489
+ self .assertEqual (len (features ), 2 )
490
+ self .assertEqual ([f ['dt' ] for f in features ], [QDate (2017 , 5 , 3 ), NULL ])
491
+
407
492
def testMetadata (self ):
408
493
""" Test that metadata is correctly acquired from provider """
409
494
0 commit comments