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